Hi could anybody help as to why the led is not staying on when i press the button, i created a function to make things easier for more leds and now the led is not staying on, Any help would be appreciated! Thanks
byte button = 2;
byte button2 = 3;
byte led = 15;
byte led2 = 14;
byte val;
byte old_val;
byte state;
void setup () {
pinMode(button, INPUT_PULLUP);
pinMode(led ,OUTPUT);
pinMode(button2, INPUT_PULLUP);
pinMode(led2 ,OUTPUT);
}
void loop (){
buttonCommand(2, 15, 0, 0, 1);
}
int buttonCommand(byte button, byte led, byte val, byte old_val, byte state) {
val = digitalRead(button);
if( val == HIGH && old_val == LOW) {
state = 1-state;
delay (10);
}
old_val = val;
if ( state == 1)
digitalWrite(led,HIGH);
else
digitalWrite(led, LOW);
}