#define LED_PORT PORTA // Port where LEDs are connected
#define LED_DDR DDRA // Data direction register for LED port
#define JOY_Y A0 // Joystick Y-axis connected to A0
#define JOY_X A2 // Joystick X-axis connected to A2
void setup() {
LED_DDR = 0xFF; // Set PORTA (A22-A29) as output (all LEDs)
}
void loop() {
int adcX = analogRead(JOY_X); // Read X-axis of the joystick
int adcY = analogRead(JOY_Y); // Read Y-axis of the joystick
uint8_t ledPattern = 0; // Default LED pattern (all LEDs OFF)
if (adcY < 300 || adcY > 700) {
ledPattern = 0xFF; // Joystick moved up or down, turn on all LEDs
} else if (adcX < 700) {
ledPattern = 0b01000000; // Joystick moved left, turn on 8th LED (A22)
} else if (adcX > 300) {
ledPattern = 0b00000001; // Joystick moved right, turn on 1st LED (A29)
}
LED_PORT = ledPattern; // Output the LED pattern to the LEDs
}