I have made it to the 11th project of the starter kit.
When i compiled the code, it gave me an error:
'prevSwitchState' was not declared in this scope
I don't know what's wrong. I typed everything out of the projects book, but it didn't show how to make the previous switch state variable.
Can you help me?
Here's the code if you need it:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int reply;
void setup() {
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print ("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop() {
switchState =digitalRead(switchPin);
if (switchState != prevSwitchState)
if (switchState == LOW) {
reply = random(8);
lcd.clear();
lcd.setCursor(0, 1);
switch(reply){
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
Here's the error:
C:\Users\vados\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\58373ecb-0049-4b7c-87cc-64c1599e2523\Crystal_Ball\Crystal_Ball.ino: In function 'void loop()':
C:\Users\vados\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\58373ecb-0049-4b7c-87cc-64c1599e2523\Crystal_Ball\Crystal_Ball.ino:15:22: error: 'prevSwitchState' was not declared in this scope
if (switchState != prevSwitchState)
^~~~~~~~~~~~~~~
C:\Users\vados\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\58373ecb-0049-4b7c-87cc-64c1599e2523\Crystal_Ball\Crystal_Ball.ino:15:22: note: suggested alternative: 'switchState'
if (switchState != prevSwitchState)
^~~~~~~~~~~~~~~
switchState
exit status 1
Compilation error: 'prevSwitchState' was not declared in this scope