Hello,
I don't really have a problem as this code is working fine but does someone know of an easier or less long winded way to implement these button reads, I have 8 Buttons wired through a resistor ladder to analog(0), one button is a shift button and because of the way the ladder is wired (all resistors in series) only one button can ever be pressed at once, so I have implimented a Boolean shift state to give each button a 2nd function, I've never really understood the "Case" keyword or if it will make any difference here,
Thanks in advance, Shaun
bool sState = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int a = analogRead(0);
if((a >= 370) && (a <= 372)) sState = 1;
Serial.println(sState);
if((a!=0) && sState == 1)
{
if((a >= 403) && (a <= 404))
{
Serial.println("F1");
sState = 0;
}
if((a >= 441) && (a <= 442))
{
Serial.println("F2");
sState = 0;
}
if((a >= 488) && (a <= 489))
{
Serial.println("F3");
sState = 0;
}
if((a >= 545) && (a <= 546))
{
Serial.println("F4");
sState = 0;
}
if((a >= 616) && (a <= 617))
{
Serial.println("F5");
sState = 0;
}
if((a >= 711) && (a <= 712))
{
Serial.println("Info");
sState = 0;
}
if((a >= 839) && (a <= 841))
{
Serial.println("Help");
sState = 0;
}
}
else
{
if((a >= 403) && (a <= 404)) Serial.println("ESC");
if((a >= 441) && (a <= 442)) Serial.println("Left Arrow");
if((a >= 488) && (a <= 489)) Serial.println("Right Arrow");
if((a >= 545) && (a <= 546)) Serial.println("Enter");
if((a >= 616) && (a <= 617)) Serial.println("PWR");
if((a >= 711) && (a <= 712)) Serial.println("Down Arrow");
if((a >= 839) && (a <= 841)) Serial.println("UP Arrow");
}
delay(100);
}