//*********************************************
//* *
//* Name Logan Dinnendahl *
//* Program name Light chaser speaker Array *
//* Date 2023-2-21 *
//* Desc First program making a light *
//* Chaser with a speaker *
//* *
//*********************************************
int delayTime = 100; // Delay time for LEDS
int buttonPin = 6; // The pin for the button
int buzzerPin = 7; // The pin for the speaker
int buttonValue = 0; // The Value of the button
int lightPattern = 1; // The pattern number
int patternArray [6][3] = {{4,12,28}, {24,20,12}, {16,8,4}, {16,24,28}, {12,20,24}, {4,8,16}} ;
int patternStep;
void setup() {
pinMode(buttonPin , INPUT_PULLUP) ; // Config for pin 8
pinMode(buzzerPin , INPUT) ; // Config for pin 7
Serial.begin(9600); // Serial setup
DDRB = B111111;
} // end setup
void loop() {
buttonValue = digitalRead(buttonPin); // reading the button
if ( buttonValue == LOW ){
tone(buzzerPin, 500, 110); // reading the tone
delay (110);
lightPattern++; // adds to the pattern number
if (lightPattern > 5) { // pattern reset condition
lightPattern = 1; // pattern reset
}
Serial.print(lightPattern); // prints the pattern number
} //end if {}
PORTB = patternArray[lightPattern] [patternStep]; // pattern running LED
delay(delayTime); // pattern delay
patternStep++; // adding 1
if (patternStep == 3){ // pattern step reset
patternStep = 0;
}
}