Go Down

Topic: problem with LiquidCrystal library?? (Read 803 times) previous topic - next topic


I've looked for previous posts, maybe I missed it.. I cannot get this library to print out any variables.. either a char or a string.. is it capable of doing this?? Keep on getting the error 'test1' was not declared in this scope.. test one is the name of the char.. My real program is way to large to fit, plus for troubleshooting I'm just trying to print any kind of variable so I opened up the example givin just try try and get something simple to work.. Thanks

* Displays text sent over the serial port (e.g. from the Serial Monitor) on
* an attached LCD.

#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
 char test1 = 'A' ;
 char Str1[6] = "test2" ;

void loop()
 // when characters arrive over the serial port...
 if (Serial.available()) {
   // wait a bit for the entire message to arrive
   // clear the screen
   // read all the available characters
   while (Serial.available() > 0) {
     // display each character to the LCD
     lcd.write(Serial.read());    // this works?? no clue why??
     lcd.print(str1);   // this won't work.. error str1 not declared in this scope
     lcd.write(test1); // this won't work.. test1 not declared in this scope..


Oct 25, 2008, 04:22 am Last Edit: Oct 25, 2008, 04:23 am by mikalhart Reason: 1
Hey, tek,

"str1" is a local variable declared inside the setup() function.  As soon as the setup() function ends, it's gone, so it's not available inside loop().  (That's what the message "not in scope" means.)  Similarly for test1.  Just move them outside the function into the "global" scope.  Also, C++ is case sensitive, so make sure you don't use Str1 in one place and str1 in another.



Thanks Mikal.. the capillization was a mistake in the posting and was correct in my actual program, but I'm just going to have to take the blame for putting the variables inside the setup loop.. Don't know how I missed that in my own program either.. Working great now..

Go Up