Pages: [1]   Go Down
Author Topic: problem with LiquidCrystal library??  (Read 500 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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()
{
  Serial.begin(9600);
  
  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
    delay(100);
    // clear the screen
    lcd.clear();
    // 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..
    }
  }
}
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 5
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Mikal
« Last Edit: October 24, 2008, 09:23:26 pm by mikalhart » Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
Logged

Pages: [1]   Go Up
Jump to: