// Define variables
byte counter1, counter2;
// The setup function runs once when you press reset or power the board
void setup() {
// Initialize counters
counter1 = 0;
counter2 = 0;
// Initialize Ports B and C pins 0-5 as outputs.
DDRB = 0b00111111;
DDRC = 0b00111111;
// Both ports start from zero
PORTB = 0;
PORTC = 0;
pinMode(2, INPUT_PULLUP); // Make bit 2 of Port D an input
pinMode(3, INPUT_PULLUP); // Make bit 3 of Port D an input
}
// The loop function runs repeatedly forever
void loop() {
// Display counter1 on PORTC and counter2 on PORTB
PORTC = counter1;
PORTB = counter2;
// Check button connected to pin 2 (increment counter1)
if (digitalRead(2) == LOW) {
counter1++;
delay(200); // Simple debounce delay
}
// Check button connected to pin 3 (increment counter2)
if (digitalRead(3) == LOW) {
counter2++;
delay(200); // Simple debounce delay
}
// Optional short delay to slow down loop execution
delay(50);
}