// **********************************************************
// * *
// * NAME : Mirza Shahriar *
// * Program Name: lightchasers.ino *
// * Date : 2023-02-21 *
// * Desc : Our first program to *
// * turn on led lights in multiple *
// * patterns and play a tone. *
// * *
// **********************************************************
int buttonPin = 6; // the pin for the button
int speakerPin = 7; // the pin for the speaker
int patternNumber = 0; // tracks what pattern I'm on
int delayTime = 100; // delay in ms between pattern steps
int patternStep = 0; // variable to track current pattern step
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(speakerPin, OUTPUT); // config speaker to be an OUTPUT
} // end setup()
void loop() {
if (digitalRead(buttonPin) == LOW ){ // check if the button is pressed
patternNumber = patternNumber + 1; // go to the next pattern
if (patternNumber == 7){ // check if the patter number goes to 7
patternNumber = 1; // reset the patter to pattern 1
} // end if
tone (speakerPin,500,100); // play the tone
delay (110); // amount of time to let go of the button
} // end if
PORTB = patternArray[patternNumber][patternStep]; // set the patter of the LED lights using the array
delay(delayTime); // 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