void glowled();
void scan();
volatile bool switchon = false; // Initially LEDs are not glowing
void setup() {
volatile char *dir = (char *)0x30;
volatile char *dirsw = (char *)0x107;
*dir = 0xFF; // Set all pins as output for LEDs
*dirsw = 0x00; // Set all pins as input for switch
}
void loop() {
glowled();
}
void glowled() {
volatile char *out = (char *)0x31;
static volatile long i = 0; // Static to keep the state between function calls
while (true) { // Continuous loop to keep the glow process running
scan(); // Always check if the button is pressed
if (switchon) {
*out = 0x01 << i; // Light up the current LED
delay(250); // Add a small delay to make the LED visible
i++; // Move to the next LED
if (i > 7) i = 0; // Wrap around after the 8th LED
} else {
// If the switch is off, hold the current LED state
// Wait until the switch is pressed again to continue
while (!switchon) {
scan(); // Keep checking for the switch press
delay(50); // Small delay to avoid rapid polling
}
}
}
}
void scan() {
volatile char *swin = (char *)0x106;
// Check if the button is pressed (active-high)
if (*swin & 0x01) {
delay(25);
switchon = !switchon; // Toggle the `switchon` state
while (*swin & 0x01); // Wait for the button to be released
}
}