MATERIALS USED
Building blocks for our mechanical wonder.
CODE USED
// Joystick Pins const int pinX = A0; // X-axis const int pinY = A1; // Y-axis const int pinSW = 7; // Button switch void setup() { // Start serial communication to see results on computer Serial.begin(9600); // The switch pin needs a "pullup" to stay stable pinMode(pinSW, INPUT_PULLUP); } void loop() { // Read the analog values (0 to 1023) int xValue = analogRead(pinX); int yValue = analogRead(pinY); // Read the button (0 = pressed, 1 = not pressed) int swValue = digitalRead(pinSW); // Print the values to the Serial Monitor Serial.print("X: "); Serial.print(xValue); Serial.print(" | Y: "); Serial.print(yValue); Serial.print(" | Button: "); Serial.println(swValue); delay(200); // Small delay so the text doesn't fly by too fast }
SCHEMATIC