简体   繁体   中英

Arduino and Color LCD Shield

I am new at Arduino and I have two questions... I found nothing on the internet about my problems:

for(int i = 0; i < 3; i++) {
  Serial.println("Test: " + i);
}

The output:

test:
est:
st:

Second problem: I am using LiquidCrystal to show a text on the display. It's a Sparkfun Color LCD Shield.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  Serial.begin(9600);
  /* NOT WORKING 
    lcd.begin(16, 2);
    lcd.print("Hello World!");
  */

}

Thanks for helping me!

The first problem is due to the fact that "Test: " + i is handled with pointer arithmetic , as opposed to string concatenation which is what you clearly have in mind. Either write Serial.print("Test: "); Serial.println(i); Serial.print("Test: "); Serial.println(i); , use proper String objects with a concatenation operator or use sprintf .

The second problem is likely caused by the fact that your lcd uses the library ColorLCDShield.h instead of the LiquidCrystal.h , and thus is handled differently than cheaper and more common displays. I suggest you to lookup the documentation specific for your Sparkfun ColorLCD model at their website , they usually provide several code examples for their components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM