/*
Name: Indervir Rai
Program Name: Arduino LED Chaser with Arrays and DDRB
Date: 2025-03-21
Program full description: This program shows the LED's turning on and off using a variety
codes that are shortened using arrays and DDRB
*/
int buttonPIN = 7; // the button is connected to pin 7
int patternNumber = 0;
int patternDelay = 100;
int twoDimArray[6][3] = {
{B001111, B011111, B111111},
{B110111, B101111, B011111},
{B100111, B010111, B001111},
{B100111, B110111, B111111},
{B011111, B101111, B110111},
{B001111, B010111, B100111}
}; // closes all the patterns
void setup() {
DDRB = B111111; // Numbers 13-8 repersented as OUTPUT
pinMode(buttonPIN, INPUT_PULLUP); /* sets pin to high voltage, and will
go to a low voltage when pressed*/
}
void loop() {
int buttonVa1 = digitalRead(buttonPIN); // read state of button
PORTB = twoDimArray [patternNumber][patternNumber];
if (buttonVa1 == LOW); // if button pressed add 1 to patternNumber
{
patternNumber++;
} // closes the pattern number increasing by 1 each time the button is pressed
if (patternNumber > 5) // resets the pattern if the number is greater than 5
{
patternNumber = 0;
}
for (int i = 0; i < 3; i++) // counts the sets of patterns also tells when to switch to next pattern
{
PORTB = twoDimArray[patternNumber][i];
delay (patternDelay);
} // closes for loop
}