const int sw = 2; // for switch pin in the joystick
void setup() {
pinMode(sw,INPUT); // set the switch pin as an input
digitalWrite(sw,HIGH); // initialze the switch as high
Serial.begin(9600); // start the serial mointor
pinMode(upLed,OUTPUT);
pinMode(downLed,OUTPUT);
pinMode(leftLed,OUTPUT);
pinMode(rightLed,OUTPUT);
}
void loop(){
if(digitalRead(sw) == LOW) {
digitalWrite(upLed,LOW);
digitalWrite(downLed,LOW);
digitalWrite(leftLed,LOW);
digitalWrite(rightLed,LOW);
}
}
here is my code the problem is, I want to press the joystick to trun on all LED's but beside if I pressed it again it should turn them all.
I know this can be done by flags but I can't remember