Rather than having the vest start in the on position, it now signals a start-up phase by the sequential lighting of the panels accompanied by ascending tones. This sets the pattern of lights on - lights off to users while nicely 'bookending' the game experience.
Here is a video...
Here is a video...
And here is the code...
// Punch Your Lights Out Vest Code
// on start: vest strike zones light up
// when a strike zone is activated (button press) the corresponding light goes out (and a buzzer sounds)
// when all lights are out a buzzer sounds
#include <Bounce2.h>
Bounce debouncerA = Bounce(); // Instantiate a Bounce object - ie. reads a button push
Bounce debouncerB = Bounce(); // Instantiate a Bounce object
Bounce debouncerC = Bounce(); // Instantiate a Bounce object
Bounce debouncerD = Bounce(); // Instantiate a Bounce object
Bounce debouncerE = Bounce(); // Instantiate a Bounce object
Bounce debouncerF = Bounce(); // Instantiate a Bounce object
const int ledA = 2; // BLACK these are the LED pins, constants won't change
const int ledB = 3; // WHITE
const int ledC = 4; // GREY
const int ledD = 5; // PURPLE
const int ledE = 6; // BLUE
const int ledF = 7; // GREEN
const int BUTTON_A = 8; // YELLOW these are the button pins, constants won't change
const int BUTTON_B = 9; // ORANGE
const int BUTTON_C = 10; // RED
const int BUTTON_D = 11; // BLACK
const int BUTTON_E = 12; // WHITE
const int BUTTON_F = 13; // GREY
const int buzzerPin = 14; // set the piezo pin number to analogue pin 0
bool ledAON = true;
bool ledBON = true;
bool ledCON = true;
bool ledDON = true;
bool ledEON = true;
bool ledFON = true;
bool ledAOFF = false;
bool ledBOFF = false;
bool ledCOFF = false;
bool ledDOFF = false;
bool ledEOFF = false;
bool ledFOFF = false;
#define frequency1 500 // sets the frequency #1
#define duration1 300 // sets the duration #1
#define frequency2 2000 // sets the frequency #2
#define duration2 800 // sets the duration #2
#define noteC 261 // sets the frequency (hertz) of the notes
#define noteCsharp 277
#define noteD 294
#define noteDsharp 311
#define noteE 330
#define noteF 349
#define noteFsharp 370
#define noteG 392
#define note Gsharp 415
#define noteA 440
void setup()
{
debouncerA.attach(BUTTON_A, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerA.interval(25); // Use a debounce interval of 25 milliseconds
debouncerB.attach(BUTTON_B, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerB.interval(25); // Use a debounce interval of 25 milliseconds
debouncerC.attach(BUTTON_C, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerC.interval(25); // Use a debounce interval of 25 milliseconds
debouncerD.attach(BUTTON_D, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerD.interval(25); // Use a debounce interval of 25 milliseconds
debouncerE.attach(BUTTON_E, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerE.interval(25); // Use a debounce interval of 25 milliseconds
debouncerF.attach(BUTTON_F, INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
debouncerF.interval(25); // Use a debounce interval of 25 milliseconds
pinMode (ledA, OUTPUT);
pinMode (ledB, OUTPUT);
pinMode (ledC, OUTPUT);
pinMode (ledD, OUTPUT);
pinMode (ledE, OUTPUT);
pinMode (ledF, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
// turn on LEDs, 2 at a time with ascending tones
delay (500);
tone(buzzerPin, noteCsharp, 600);
digitalWrite (ledF, ledFON);
digitalWrite (ledA, ledAON);
delay (600);
tone(buzzerPin, noteD, 600);
digitalWrite (ledE, ledEON);
digitalWrite (ledB, ledBON);
delay (600);
tone(buzzerPin, noteE, 600);
digitalWrite (ledC, ledCON);
digitalWrite (ledD, ledDON);
delay (600);
tone(buzzerPin, noteA, 600);
delay (600);
}
void loop()
{
debouncerA.update(); // Update the Bounce instance
debouncerB.update(); // Update the Bounce instance
debouncerC.update(); // Update the Bounce instance
debouncerD.update(); // Update the Bounce instance
debouncerE.update(); // Update the Bounce instance
debouncerF.update(); // Update the Bounce instance
if (debouncerA.fell()) // press button A
{
ledAON = false;
Serial.print("hitA"); // remembers the button press
digitalWrite (ledA, ledAOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
if (debouncerB.fell()) // press button B
{
ledBON = false;
Serial.print("hitB"); // remembers the button press
digitalWrite (ledB, ledBOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
if (debouncerC.fell()) // press button C
{
ledCON = false;
Serial.print("hitC"); // remembers the button press
digitalWrite (ledC, ledCOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
if (debouncerD.fell()) // press button D
{
ledDON = false;
Serial.print("hitD"); // remembers the button press
digitalWrite (ledD, ledDOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
if (debouncerE.fell()) // press button E
{
ledEON = false;
Serial.print("hitE"); // remembers the button press
digitalWrite (ledE, ledEOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
if (debouncerF.fell()) // press button F
{
ledFON = false;
Serial.print("hitF"); // remembers the button press
digitalWrite (ledF, ledFOFF);
tone(buzzerPin, frequency1, duration1); //( pin number, frequency in hertz, duration in milliseconds);
}
// once all buttons have been hit once play an end of game tone then STOP all functions
if (!ledAON && !ledBON && !ledCON && !ledDON && !ledEON && !ledFON)
{ delay (500);
tone(buzzerPin, noteG, 300);
delay (600);
tone(buzzerPin, noteF, 300);
delay (600);
tone(buzzerPin, noteE, 300);
delay (600);
tone(buzzerPin, noteD, 300);
delay (600);
tone(buzzerPin, noteCsharp, 1000);
delay (1000);
while (1); // STOP hammertime
}
}
Comments
Post a Comment