// ***************************************************************
// * *
// * NAME : Shaan Sandhu *
// * Program Name : lighchaser.ino *
// * Date : 2023-03-08 *
// * Desc : This program puts a pattern on our led light *
// * with speed control *
// * along with a sound *
// * *
// ***************************************************************
int timeDelayMultiplier = 0; // multiplies the delay between patterns
int buttonPin = 6; // the pin for the button
int patternNumber = 0; // tracks what pattern I'm on
int patternStep = 0; // variable to track current pattern step
int timer = 0; // timer for the speed of the pattern
int sensor = A0; // sensor senses the input speed
int delayTime = 100; // delay in ms between pattern steps
int patternArray [6][3] = { {4,12,32} , {24,20,12} , {16,8,4} , {16,24,32} , {12,20,24} , {4,8,16} }; // array with all 6 patterns for LEDs in demcimal
void setup() {
DDRB = B111111; // set all PORTB pins as outputs
pinMode(buttonPin, INPUT_PULLUP); // config button to be an INPUT
pinMode(7, OUTPUT); // config speaker on pin 7
Serial.begin (9600); // initializing the serial moniter
} // end setup()
void loop() {
timeDelayMultiplier = (analogRead(sensor)/100) +1; //1023/100 ---> 10-0 ---> +1(11,1)
timer = delayTime *timeDelayMultiplier; // delays time in the pattern
if (digitalRead(buttonPin) == LOW ){ // check if the button is pressed
patternNumber = patternNumber + 1; // go to the next pattern
if (patternNumber == 7){ // check if the pattern number goes to 7
patternNumber = 1; // reset the pattern to pattern 1
} // end if
tone; (7,500,100); // play the tone
delay (110); // amount of time to let go of the button
} // end if
PORTB = patternArray[patternNumber][patternStep]; // set the pattern of the LED lights using the array
delay(timer); // delay for the pattern to keep running
patternStep++; // change the pattern to the next step
if(patternStep == 3){ // check to see if the pattern is on step 3
patternStep = 0; // reset pattern
}
} // end loop