So I am working with Gizduino (Arduino clone), keypad and led. What am I doing is getting the value of keypressed and then light up the led according to the value (eg., when I pressed 2 on the keypad 2 LEDs will blink). I know this is just basic but please bear with me. I have this code (I will not include some really basic things like keymapping or something that is not related to my question).
int led1 = A0;
int led2 = A1;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop()
{
char keypressed = myKeypad.getKey();
if(keypressed != NO_KEY)
{
if(keypressed > 47 && keypressed < 58) // is between '0' and '9'
{
if(!mySwitch)
{
num1 = (num1 * 10) + (keypressed - 48);
}
else
{
num2 = (num2 * 10) + (keypressed - 48);
}
if(keypressed = '1')
{
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1,LOW);
delay(500);
}
if(keypressed = '2')
{
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2,LOW);
delay(500);
}
}
}
What's happening is that when I press '1' in the keypad the first led will blink and after that the second one will too. Why is this happening? Is there a problem in my code?