int switchValue, xValue, yValue; //declare variables
void setup() {
pinMode(2, INPUT);
digitalWrite(2, HIGH);
Serial.begin(9600);
}
void loop() {
switchValue=digitalRead(2); //read the button
xValue=analogRead(A0); //read x-axis
yValue=analogRead(A1); //read y-axis
Serial.print("Switch: ");
Serial.println(switchValue);
Serial.print("X-axis: ");
Serial.println(xValue);
Serial.print("Y-axis: ");
Serial.println(yValue);
Serial.print("\n\n");
delay(1000);
}
Challenge: Get the joystick to control 4 lights, push it right one light turns on, left another, up another and down another. All lights should turn off when the joystick is in the middle.