#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t ledPattern = 0b00000001; // Initial pattern for LEDs
void setup() {
// Set the LED pins as outputs (pins 0 to 7)
for (int pin = 0; pin <= 7; pin++) {
pinMode(pin, OUTPUT);
}
// Initialize Timer1
noInterrupts(); // Disable all interrupts
TCCR1A = 0; // Set entire TCCR1A register to 0
TCCR1B = 0; // Same for TCCR1B
TCNT1 = 0; // Initialize counter value to 0
OCR1A = 39062; // Set compare match register for 0.25s intervals (16 MHz clock / 256 prescaler / 0.25s - 1)
TCCR1B |= (1 << WGM12); // Turn on CTC mode
TCCR1B |= (1 << CS12); // Set CS12 bit for 256 prescaler
TIMSK1 |= (1 << OCIE1A); // Enable timer compare interrupt
interrupts(); // Enable all interrupts
}
ISR(TIMER1_COMPA_vect) {
// Rotate the LED pattern to the right
if (ledPattern & 0b00000001) {
ledPattern = (ledPattern >> 1) | 0b10000000;
} else {
ledPattern >>= 1;
}
// Output the LED pattern to the pins
for (int i = 0; i < 8; i++) {
digitalWrite(i, (ledPattern >> i) & 0x01);
}
}
void loop() {
}