Greetings Arduino enthusiasts!
I've been tasked with building a control system for a project run by a group of mechanical engineers at my Uni, and I've ran into what seems to be a very bizarre problem.
I have declared the Liquidcrystal library at the start of my code, and it works flawlessly in the setup stage. However, anything starting with "lcd." within the main program loop generates the error:
"CODE_CODE_CODE_MAIN_CODE.ino: In function 'void loop()':
CODE_CODE_CODE_MAIN_CODE.ino:77:2: error: 'lcd' was not declared in this scope
Error compiling."
My Arduino Due seems to be setup correctly, as all of the example code that loops lcd commands work fine.
Below is my code (very much a work in progress)
#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>
#include <LiquidCrystal.h>
void setup() {
Serial.begin(9600);
analogReadResolution(12); //Setting sensor resolution to 12-bits
//************************* LCD INITIALISATION ****************************
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(48, 49, 44, 45, 46, 47);
// RS E D4 D5 D6 D7
lcd.begin(16, 2); // setting 2 rows of 16 digits
lcd.clear();
lcd.print("Initializing...");
delay(1000);
//************************* SD INITIALISATION ***************************
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(4, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(4)) { //CS pin 4
lcd.setCursor(0, 1);
lcd.print("SD Card failed"); // don't do anything more:
return;
}
// clear the SD card
if (SD.exists("300KHz.txt")) {
lcd.clear();
lcd.print("Clearing card");
SD.remove("300KHz.txt");
delay(1000);
}
lcd.clear();
lcd.print("card initialized.");
delay(1000);
//******************************* SET SCAN DISTANCE *********************************
int scanDistance = 6252;
lcd.clear();
lcd.print("Scan");
lcd.setCursor(5,0);
lcd.print(scanDistance);
}
//***********************************************************************************
// ****************************** MAIN PROGRAM LOOP ********************************
void loop() {
//**************************** QUERY GPS **************************************
// float currentspeed;
//***************************** LOG DATA ***********************************
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("300KHz.txt", FILE_WRITE);
if (dataFile) { // if the file is available, write to it:
dataFile.println(3.3*analogRead(61)/4096);
dataFile.close();
}
lcd.setCursor(0,1);
lcd.print(analogRead(61));
//******************************* ADJUST SPEED *********************************
}
Any suggestions would be greatly appreciated! While the project should be completely autonomous after the setup stage, some realtime feedback would be nice.
Thanks
Liam