#include "mylib.h"
#define smalldelay 200000 // A small delay duration, specific to the hardware being used
#define delay10s 10000 // Delay for 10 seconds in milliseconds
#define delay30s 30000 // Delay for 30 seconds in milliseconds
void setup() {
// Initialization code, runs once when the program starts
myinit();
}
// Function to output a pattern with specified delays
void timedOutput(int pattern[], int size, int delay) {
// Loop through the pattern array and output each value with a delay in between
for (int i = 0; i < size; i++) {
output(pattern[i]);
timedelay(delay); // Custom delay function
}
}
// Function to check if a switch is pressed and execute the corresponding output pattern
void checkAndExecute(int switchMask, int pattern[], int size, int delay) {
// Check if the specified switch is pressed using the switch mask
if (input() & switchMask) {
timedOutput(pattern, size, delay); // Execute the output pattern with delays
}
}
void loop() {
// Reset all outputs at the beginning of each loop iteration
output(0x00);
// 1. Press 2nd switch to sequentially light up LEDs:
// First LED, delay, second LED, delay, fifth LED, delay, sixth LED
int pattern1[] = {0x02, 0x04, 0x20, 0x40};
checkAndExecute(0x04, pattern1, 4, smalldelay);
// 2. Press 3rd switch to sequentially light up LEDs:
// Third LED, delay, first LED, delay, seventh LED, delay, fourth LED
int pattern2[] = {0x08, 0x02, 0x80, 0x10};
checkAndExecute(0x08, pattern2, 4, smalldelay);
// 3. Press 2nd switch to sequentially light up LEDs:
// Zeroth LED, delay, first LED, delay, fifth LED, delay, sixth LED
int pattern3[] = {0x01, 0x02, 0x20, 0x40};
checkAndExecute(0x04, pattern3, 4, smalldelay);
// 4. Press 7th switch to sequentially light up LEDs:
// Zeroth LED, delay, first LED, delay, fourth LED, delay, seventh LED
int pattern4[] = {0x01, 0x02, 0x10, 0x80};
checkAndExecute(0x80, pattern4, 4, smalldelay);
// 5. Press 3rd switch to sequentially light up LEDs:
// Seventh LED, delay, sixth LED, delay, third LED, delay, second LED
int pattern5[] = {0x80, 0x40, 0x08, 0x04};
checkAndExecute(0x08, pattern5, 4, smalldelay);
// 6. Press 2nd switch to sequentially light up LEDs:
// Third LED, delay, fifth LED, delay, seventh LED, delay, sixth LED
int pattern6[] = {0x08, 0x02, 0x80, 0x40};
checkAndExecute(0x04, pattern6, 4, smalldelay);
// 7. Press 7th switch to sequentially light up LEDs:
// Fifth LED, delay, third LED, delay, zeroth LED, delay, first LED
int pattern7[] = {0x20, 0x08, 0x01, 0x02};
checkAndExecute(0x80, pattern7, 4, smalldelay);
// 8. Press 1st switch and glow the 5th LED for 30 seconds
if (input() & 0x02) {
output(0x20);
delay(delay30s); // Using delay function for a 30-second duration
}
// 9. Sequential switch presses to glow the 8th LED:
// Press 1st switch for 10 seconds, followed by 4th, 7th, and 9th switches with a small delay
if (input() & 0x01) {
output(0x80);
delay(delay10s); // Using delay function for a 10-second duration
}
if (input() & 0x10) {
output(0x80);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x40) {
output(0x80);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x100) {
output(0x80);
timedelay(smalldelay); // Custom delay function
}
// 10. Sequential switch presses to glow the 5th LED:
// Press 1st, 4th, 7th, and 9th switches with a small delay for each
if (input() & 0x01) {
output(0x20);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x10) {
output(0x20);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x40) {
output(0x20);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x100) {
output(0x20);
timedelay(smalldelay); // Custom delay function
}
// Turn off the 5th LED sequentially by pressing 4th, 7th, 9th, and 8th switches
if (input() & 0x10) {
output(0x00);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x40) {
output(0x00);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x100) {
output(0x00);
timedelay(smalldelay); // Custom delay function
}
if (input() & 0x80) {
output(0x00);
timedelay(smalldelay); // Custom delay function
}
}