Joystick as switch

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

Have you tried to compile that code??

Your sketch says "sw" uses pin 2...

You will need to do the same with upLed, downLed, leftLed and rightLed.

There is more work to be done after you get that done.

Look at the state change detection example that comes with the IDE.

It does not sound like you have a problem with IDE 1.x and hence your topic has been moved to a more suitable section of the forum.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.