Go Down

Topic: Error code "lcd not declared in this scope" (Read 78 times) previous topic - next topic

delaware900

I am using an Arduino UNO r3 with a 16x2 QPASS LCD and I2C backpack.  I have not been able to compile the attached code. The code hangs up on lcd.set cursor and lcd.clear commands at the end of the code but each time I fixed the one error it jumped to the same code in a different part of the sketch.  I tried the sketch with the various I2C libraries and the HD44780 seemed to work the best. Any help would be greatly appreciated.

Code: [Select]


#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header


// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;


const int WAITING = 1;
const int S_2 = 2;
const int S_3 = 3;
const int READY = 4;
const int stoptime = 5;

////  VARIABLES  ////

float distance = 20.00; //USER SETTING: Change number to measured distance between sensors in INCHES  CDH
float scale = 87.1;      // USER SETTING:  THIS IS FOR HO SCALE. Change as needed for other scales. CDH
float starttime, finish, elapsed, miles, hours, mph, scaleMPH;
int sensorLeft = 4;
int sensorRight = 5;
int leftValue;
int  rightValue;
int var = READY;


void setup()
{
  pinMode(sensorLeft, INPUT);
  pinMode(sensorRight, INPUT);
  lcd.begin(16, 2);  // initialize the lcd for 16 chars 2 lines, turn on backlight
  lcd.backlight(); // LCD backlight on
  lcd.clear();
  lcd.setCursor(16, 2);
}


void loop() {

  switch (var) {

    case READY:
      lcd.setCursor(col, 0);
      lcd.print("READY");
      var = WAITING;
      break;
  }
case WAITING:
  leftValue = digitalRead(sensorLeft);
  if (leftValue == 0) {
    starttime = millis();
    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("STARTED");
    var = S_2;
 }
{  rightValue = digitalRead(sensorRight);
  if (rightValue == 0)]{
    starttime = millis();
    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("STARTED");
    var = S_3;
 }
  break;

case S_2:
  rightValue = digitalRead(sensorRight);
  if (rightValue == 0) {
    finish = millis();
    var = stoptime;
  }
  break;

case S_3:
  leftValue = digitalRead(sensorLeft);
  if (leftValue == 0) {
    finish = millis();
    var = stoptime;
  }
  break;

case stoptime:
  elapsed = finish - starttime; // millis
  elapsed = elapsed / 1000; // seconds
  miles = distance / 63360; // miles
  hours = elapsed / 3600; // hours
  mph = miles / hours;
  scaleMPH = mph * scale;
} {
    lcd.clear();}{
    lcd.setCursor(4, 0);
    lcd.print(scaleMPH);
    lcd.setCursor(13, 1);
    lcd.print("MPH");

    delay(15000);

    var = READY;
    break;
  }



pert

The error didn't lie. You never created the lcd object. Please take some time to study File > Examples > hd44780 > ioClass > hd44780_I2Clcd > HelloWorld so you can learn how to use the library properly.

Go Up