/*
***************************************************************************************************
***************************************************************************************************
* Name: Ali Faour *
* Project Name: LightChaser Arrays *
* Date: 24-09-2024 *
* Description: Loop through set of lights from 1-5, creating different patterns and combinations *
* of lights. Go through patterns with if statements. All patterns/combinations are *
* shown in the light pattern array *
***************************************************************************************************
***************************************************************************************************
*/
int buttonPin = 7; // set the button to pin number 7
int patternNumber = 0; // start the program at the first pattern
int speedValue = 3000; // make the speed value 300
int pinNumberRed = 13; // set the red led to pin 13
int pinNumberYellow = 12; // set the yellow led to pin 12
int pinNumberGreen = 11; // set the green led to pin 11
int analogInputSpeed = A0; // set the analog input in pin A0
void setup() {
Serial.begin(9600);
DDRB = B111111;
pinMode(buttonPin, INPUT_PULLUP); // make the button pin an input
}//setup()
int patternCounter = 0;
int lightPattern [6][3] = { { 8, 24, 56}, // makes the led light up in all shown patterns
{48, 40, 24},
{32, 16, 8},
{32, 48, 56},
{24, 40, 48},
{8, 16, 32},
};
void loop() {
speedValue = analogRead(analogInputSpeed); // set speed value to analog input speed
if ( digitalRead(buttonPin) == LOW) { // check if button was pressed
patternNumber++; // if it is pressed, move to the next pattern number
if (patternNumber > 5) { // if pattern number is higher than 5
patternNumber = 0; // set pattern number back to 0
}//end if()
}
for(int x = 0; x < 3; x++) { // pattern goes through 3 steps and resets
PORTB = lightPattern [patternNumber] [x]; // set port b to the value/pattern in the array
delay(speedValue); // wait
}
Serial.println(patternNumber); // prints the pattern number
}//end loop()