//roborobot all rights reserved
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
int sensorValuex = analogRead(A0);//for x value
int sensorValuey = analogRead(A1);//for y value
int sensorValueb = analogRead(A2);//for button
if (sensorValueb == LOW){ //if you press the button
// print out the value you read:
Serial.println(sensorValuex); //show x value
}// print out the value you read:
else{Serial.println(sensorValuey); //if button has not been pressed show y value
}
delay(1); // delay in between reads for stability
}
//end
//check out
//www.hackster.io/roborobotno0/joystick-control-c0bd5f
//that is where this sketch came from
Comments