// For Arduino Uno, Digital Pin 13 is connected to PB5 (Port B, Bit 5) on the ATmega328P microcontroller.
// DDRB: Data Direction Register for Port B. Controls whether a pin is INPUT (0) or OUTPUT (1).
// PORTB: Port B Data Register. Controls the HIGH (1) or LOW (0) state of an OUTPUT pin.
void setup() {
// Set Digital Pin 13 (PB5) as an OUTPUT.
// We do this by setting the 5th bit of the DDRB register to 1.
DDRB |= (1 << PB5); // |= is bitwise OR assignment. (1 << PB5) creates a bitmask with only PB5 set.
// This effectively sets PB5 to 1 without affecting other bits in DDRB.
}
void loop() {
// Turn the LED on (HIGH).
// We do this by setting the 5th bit of the PORTB register to 1.
PORTB |= (1 << PB5); // Sets PB5 to HIGH.
delay(500); // Wait for 500 milliseconds (using a standard Arduino delay for simplicity)
// Turn the LED off (LOW).
// We do this by clearing the 5th bit of the PORTB register to 0.
PORTB &= ~(1 << PB5); // &= ~ is bitwise AND NOT assignment. It clears the specified bit.
// ~(1 << PB5) creates a mask with all bits set EXCEPT PB5.
// This effectively sets PB5 to LOW without affecting other bits in PORTB.
delay(500); // Wait for 500 milliseconds
}