I've tried searching for the answer first but everyone asking this question had their variables declared in the setup loop, but I'm pretty sure all my variables are global. I haven't used the arduino in quite a while so I'm trying to work out the kinks; this doesn't make sense though...
The error is referencing the first IF statement in the loop() function and is telling me 'thatButton' is not declared in that scope. This code was copied directly from the Jeremy Blum Arduino book and, while not the first time I've tried this code, this is the first time I've had scope issues like this.
const int BLED=9;
const int GLED=10;
const int RLED=11;
const int BUTTON=2;
boolean thatButton = LOW;
boolean currentButton = LOW;
int ledMode = 0;
void setup() {
// put your setup code here, to run once:
pinMode(BLED, OUTPUT);
pinMode(GLED, OUTPUT);
pinMode(RLED, OUTPUT);
pinMode(BUTTON,INPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON);
if (last != current)
{
delay(5);
current = digitalRead(BUTTON);
}
return current;
}
void setMode(int mode)
{
if (mode == 1)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
else if (mode == 2)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
else if (mode == 3)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
else if (mode == 4)
{
digitalWrite(RLED, 127);
digitalWrite(GLED, 0);
digitalWrite(BLED, 127);
}
else if (mode == 5)
{
digitalWrite(RLED, 0);
digitalWrite(GLED, 127);
digitalWrite(BLED, 127);
}
else if (mode == 6)
{
digitalWrite(RLED, 127);
digitalWrite(GLED, 127);
digitalWrite(BLED, 0);
}
else if (mode == 7)
{
digitalWrite(RLED, 85);
digitalWrite(GLED, 85);
digitalWrite(BLED, 85);
}
else if (mode == 0)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
currentButton = debounce(thatButton);
if (thatButtton == LOW && currentButton == HIGH)
{
ledMode++;
}
thatButton = currentButton;
if (ledMode == 8) ledMode = 0;
setMode(ledMode);
}