void setup() {
// Set the LED pin (D5) as an output Using DDRD register
DDRD |= (1 << DDD5);
// Set the button pin (D9) as an input with internal pull-up resistor Using DDRB register
DDRB &= ~(1 << DDB1); // Clear the 1st bit to configure it as input
PORTB |= (1 << PORTB1); // Set the 1st bit to enable the pull-up resistor
}
void loop() {
// Flip the state of the LED pin Using PIN register to toggle the state
PIND |= (1 << PIND5);
// Delay based on the button state
delay((PINB & (1 << PINB1)) ? 300 : 100);
}
/*
const byte ledPin = 5;
const byte buttonPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
digitalWrite(ledPin, digitalRead(ledPin) == LOW ? HIGH : LOW); // flip pin state
delay(digitalRead(buttonPin) == LOW ? 100 : 300); // if button is pressed wait less (but keep it visible)
}
*/