/*
*****************************************
*****************************************
** **
**NAME: Lucas Branton **
**Program: pattern Lightshow(V2) **
**Date: 2024/9/13 **
**Description: This project presents **
** light patterns that can **
** be switched using the **
** button. WITH INPUT **
** pullup **
** **
*****************************************
*****************************************
*/
int redLED = 13; // this integer respresents the red LED, it equals 13 because the red LED is attached to the 13th section of the Arduino
int yellowLED = 12; // this integer respresents the yellow LED, it equals 12 because the yellow LED is attached to the 12th section of the Arduino
int greenLED = 11; // this integer respresents the green LED, it equals 11 because the green LED is attached to the 11th section of the Arduino
int pushButton = 7; // this integer respresents button, it equals 7 because the button is attached to the 7th section of the Arduino
int patternNumber = 0; // integer that respresents the current opatterns number
int speedValue = 400; // speed value will be the delay for all the code, this delay is 400 miliseconds long
void setup() {
DDRB = B111111;
pinMode(pushButton, INPUT_PULLUP); //allows the button to become activated as an input
Serial.begin(9600); //allows 960 characters to be read in a second
}
void loop() {
if ( digitalRead(pushButton) == LOW ) { //if the button is pushed...
patternNumber ++; //change the pattern, in reality we are actually changing the value of the pattern number variable whitch changes the pattern
if (patternNumber > 5) { //if the pattern number is over 5...
patternNumber = 0 ; //reset the pattern number back to pattern 0 `
} // end if()
}// end if()
if (patternNumber == 0) { //if the pattern number variable equals 0, then we get the values 8, 24, 56
PORTB = B001000; //8 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B011000; //24 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B111000; //56 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
} else if (patternNumber == 1) { //otherwise, if the pattern number variable equals 1, then we get the values 48, 40, 24
PORTB = B110000; //48 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B101000; //40 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B011000; //24 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
} else if (patternNumber == 2) { //otherwise, if the pattern number variable equals 2, then we get the values 32, 26, 8
PORTB = B100000; //32 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B010000; //16 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B001000; //8 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
} else if (patternNumber == 3) { //otherwise, if the pattern number variable equals 3, then we get the following pattern...
PORTB = B100000; //32 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B110000; //48 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B111000; //56 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
} else if (patternNumber == 4) { //otherwise, if the pattern number variable equals 4, then we get the following pattern...
PORTB = B011000; //24 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B101000; //40 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B110000; //48 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
} else { //otherwise, if the pattern number variable equals anything else, then we get the following pattern...
PORTB = B001000; //8 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B010000; //16 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
PORTB = B100000; //32 in decimal
delay (speedValue); //delays the wait time to a 400 milisecond wait between pattern sequences
}
Serial.println(patternNumber); //prints the pattern number every time the pattern changes
}