|
@@ -1,3 +1,6 @@
|
|
|
+/* This code is in all sorts of disarray. Trust nothing. */
|
|
|
+/* Notably, the `ws2812_*` functions are unused, I think */
|
|
|
+
|
|
|
/*
|
|
|
Cider Drag Races
|
|
|
|
|
@@ -37,9 +40,9 @@
|
|
|
Licensed under GPLv3: https://www.gnu.org/licenses/gpl.html
|
|
|
*/
|
|
|
#include <SoftwareSerial.h>
|
|
|
-#include "Adafruit_NeoPixel.h"
|
|
|
-#include "WS2812_Definitions.h"
|
|
|
+#include <WS2812_Definitions.h>
|
|
|
#include <eRCaGuy_ButtonReader.h>
|
|
|
+#include <BackgroundRingClass.h>
|
|
|
|
|
|
/**********
|
|
|
CONFIGURATION SECTION
|
|
@@ -52,7 +55,7 @@
|
|
|
Lots of help for this example at
|
|
|
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-11-using-a-piezo-buzzer
|
|
|
*/
|
|
|
-const int debug = 1;
|
|
|
+const int debug = 0;
|
|
|
|
|
|
const int buzzerPin = 9;
|
|
|
const unsigned long songFrequency = 90000; // How frequently the song may play in seconds
|
|
@@ -72,9 +75,9 @@ const int brightness = 255;
|
|
|
Two strips of 6 LEDs connected to 5V and Ground, plus the signal pin
|
|
|
*/
|
|
|
//const int ledPinsLeft[] = {30, 32, 34, 36, 38};
|
|
|
-const int ledPinsLeft[] = {38, 36, 34, 32, 30};
|
|
|
+const int ledPinsRight[] = {38, 36, 34, 32, 30};
|
|
|
//const int ledPinsRight[] = {31, 33, 35, 37, 39};
|
|
|
-const int ledPinsRight[] = {39, 37, 35, 33, 31};
|
|
|
+const int ledPinsLeft[] = {39, 37, 35, 33, 31};
|
|
|
|
|
|
const unsigned long prettyLEDFrequency = 30; // How frequently something pretty happens on the LEDs
|
|
|
const float prettyLEDProbability = 0.75; // Probability that the song will play during that frequency
|
|
@@ -82,16 +85,16 @@ const float prettyLEDProbability = 0.75; // Probability that the song will play
|
|
|
/* Christmas Tree */
|
|
|
const unsigned long startDelay = 1000; /* How long to wait between hitting the start ubtton and starting */
|
|
|
const unsigned long maxDelay = 5000; /* In non dragrace mode, how long might we wait *after* a guaranteed startDelay? */
|
|
|
-const unsigned long lightDelay = 500; /* How long to wait between lights during the countdown */
|
|
|
+const unsigned long lightDelay = 600; /* How long to wait between lights during the countdown */
|
|
|
const unsigned long topColor = PURPLE; /* Top LED is constant to show power */
|
|
|
|
|
|
/* 7-Segment Display Setup
|
|
|
Two 7 OpenSegment displays from SparkFun in serial mode.
|
|
|
*/
|
|
|
-const int leftDisplayTX = 3;
|
|
|
-const int rightDisplayTX = 2;
|
|
|
-const int leftDisplayRX = 5; /* Unused */
|
|
|
-const int rightDisplayRX = 4; /* Unused */
|
|
|
+const int leftDisplayTX = 2;
|
|
|
+const int rightDisplayTX = 3;
|
|
|
+const int leftDisplayRX = 4; /* Unused */
|
|
|
+const int rightDisplayRX = 5; /* Unused */
|
|
|
|
|
|
/* Force Sensitive Resistor Switches (Analog inputs) */
|
|
|
//const int leftFSR = A7;
|
|
@@ -106,8 +109,8 @@ const int leftReadyButtonPin = 13;
|
|
|
const int rightReadyButtonPin = 8;
|
|
|
|
|
|
/* Difficulty */
|
|
|
-const int difficultyLeftPin = 46;
|
|
|
-const int difficultyRightPin = 47;
|
|
|
+//const int difficultyLeftPin = 46;
|
|
|
+//const int difficultyRightPin = 47;
|
|
|
|
|
|
/* Loop delays
|
|
|
n.b. It occurs to me that unusual values for these variables /may/ upset
|
|
@@ -141,16 +144,16 @@ const unsigned long debounceDelay = 250;
|
|
|
Application Variables
|
|
|
*/
|
|
|
unsigned long lastSongCheck = 0;
|
|
|
-Adafruit_NeoPixel rightRing = Adafruit_NeoPixel(LED_COUNT + 1, ledPinRight, NEO_GRB + NEO_KHZ800);
|
|
|
-Adafruit_NeoPixel leftRing = Adafruit_NeoPixel(LED_COUNT + 1, ledPinLeft, NEO_GRB + NEO_KHZ800);
|
|
|
+BackgroundRingClass rightRing = BackgroundRingClass(LED_COUNT, ledPinRight);
|
|
|
+BackgroundRingClass leftRing = BackgroundRingClass(LED_COUNT, ledPinLeft);
|
|
|
|
|
|
SoftwareSerial leftDisplay(leftDisplayRX, leftDisplayTX);
|
|
|
SoftwareSerial rightDisplay(rightDisplayRX, rightDisplayTX);
|
|
|
|
|
|
eRCaGuy_ButtonReader leftReadyButton = eRCaGuy_ButtonReader(leftReadyButtonPin);
|
|
|
eRCaGuy_ButtonReader rightReadyButton = eRCaGuy_ButtonReader(rightReadyButtonPin);
|
|
|
-eRCaGuy_ButtonReader leftFSRButton = eRCaGuy_ButtonReader(leftFSRSimPin);
|
|
|
-eRCaGuy_ButtonReader rightFSRButton = eRCaGuy_ButtonReader(rightFSRSimPin);
|
|
|
+eRCaGuy_ButtonReader leftFSRButton = eRCaGuy_ButtonReader(leftFSRSimPin, 25);
|
|
|
+eRCaGuy_ButtonReader rightFSRButton = eRCaGuy_ButtonReader(rightFSRSimPin, 25);
|
|
|
eRCaGuy_ButtonReader clearToggle = eRCaGuy_ButtonReader(clearPin);
|
|
|
|
|
|
|
|
@@ -185,16 +188,12 @@ long leftClock = 0;
|
|
|
Code
|
|
|
*/
|
|
|
void setup() {
|
|
|
- Serial.begin(9600); // Serial used for logging
|
|
|
+ Serial.begin(115200); // Serial used for logging
|
|
|
|
|
|
/* Buzzer Setup */
|
|
|
pinMode(buzzerPin, OUTPUT);
|
|
|
randomSeed(analogRead(randomPin));
|
|
|
|
|
|
-
|
|
|
- /* WS2812 LED Setup */
|
|
|
- rightRing.begin();
|
|
|
- leftRing.begin();
|
|
|
/* Digital LED Setup */
|
|
|
for(int i = 0; i < 5; i++) {
|
|
|
pinMode(ledPinsLeft[i], OUTPUT);
|
|
@@ -204,6 +203,8 @@ void setup() {
|
|
|
}
|
|
|
/* clearLEDs(); */
|
|
|
clearLEDs();
|
|
|
+ rightRing.setColor(BLACK, 255, true);
|
|
|
+ leftRing.setColor(BLACK, 255, true);
|
|
|
|
|
|
/* 7 Segment Displays */
|
|
|
leftDisplay.listen();
|
|
@@ -216,7 +217,7 @@ void setup() {
|
|
|
rightDisplay.write('v');
|
|
|
rightDisplay.write(0x7A);
|
|
|
rightDisplay.write((byte) brightness);
|
|
|
- longbeep();
|
|
|
+ longbeep(); delay(400);
|
|
|
printClocks(1223,1996);
|
|
|
|
|
|
/* Initialize our buttons */
|
|
@@ -233,48 +234,78 @@ void setup() {
|
|
|
pinMode(buzzPin, INPUT_PULLUP); /* White */
|
|
|
|
|
|
/* And our sliders */
|
|
|
- pinMode(difficultyLeftPin, INPUT_PULLUP); /* HIGH is normal difficulty */
|
|
|
- pinMode(difficultyRightPin, INPUT_PULLUP);
|
|
|
+ //pinMode(difficultyLeftPin, INPUT_PULLUP); /* HIGH is normal difficulty */
|
|
|
+ //pinMode(difficultyRightPin, INPUT_PULLUP);
|
|
|
|
|
|
/* Demo the Christmas Tree */
|
|
|
setLEDs(BLACK, BLACK, BLACK, BLACK, YELLOW);
|
|
|
- longbeep(); delay(400);
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, 0, beepDuration);
|
|
|
+ mydelay(400);
|
|
|
setLEDs(BLACK, BLACK, BLACK, YELLOW, BLACK);
|
|
|
- longbeep(); delay(400);
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, 0, beepDuration);
|
|
|
+ mydelay(400);
|
|
|
setLEDs(BLACK, BLACK, YELLOW, BLACK, BLACK);
|
|
|
- longbeep(); delay(400);
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, 400, buzzerPin, 0, beepDuration);
|
|
|
+ mydelay(400);
|
|
|
+ delay(100);
|
|
|
setLEDs(BLACK, GREEN, BLACK, BLACK, BLACK);
|
|
|
- longbeep(); delay(400);
|
|
|
- setLEDs(RED, BLACK, BLACK, BLACK, BLACK);
|
|
|
+ //rightRing.init_pulse_and_beep(DARKGREEN, 80, 1000, buzzerPin, beepFrequency, 300);
|
|
|
+ //leftRing.init_pulse_and_beep(DARKGREEN, 80, 1000, buzzerPin, 0, 300);
|
|
|
+ leftRing.init_solid(DARKGREEN, 80);
|
|
|
+ rightRing.init_solid(DARKGREEN, 80);
|
|
|
longbeep();
|
|
|
+ delay(1000);
|
|
|
+ setLEDs(BLACK, BLACK, BLACK, BLACK, BLACK);
|
|
|
+ rightRing.init_idle();
|
|
|
+ leftRing.init_idle();
|
|
|
+ //longbeep();
|
|
|
|
|
|
- /* Demo the rings */
|
|
|
- red_green_pulse();
|
|
|
-
|
|
|
/* 7 Segment Display Continued */
|
|
|
- if(random(0, 1000) < 100) {
|
|
|
+ int special_clocks = random(0, 1000);
|
|
|
+ if(special_clocks < 100) {
|
|
|
+ // BOOBIES!
|
|
|
leftClock=531;
|
|
|
rightClock=8008;
|
|
|
printClocks(leftClock, rightClock);
|
|
|
+ } else if(special_clocks < 200) {
|
|
|
+ leftClock=1223;
|
|
|
+ rightClock=2025;
|
|
|
+ printClocks(leftClock,rightClock);
|
|
|
} else {
|
|
|
leftClock=1223;
|
|
|
rightClock=2016;
|
|
|
printClocks(leftClock,rightClock);
|
|
|
}
|
|
|
- longbeep();
|
|
|
+ //longbeep();
|
|
|
|
|
|
/* start button */
|
|
|
//pinMode(startButtonPin, INPUT_PULLUP);
|
|
|
Serial.println("Setup complete.");
|
|
|
}
|
|
|
|
|
|
+void mydelay(int ms) {
|
|
|
+ // things we do during delays
|
|
|
+ unsigned long starttime = millis();
|
|
|
+ while(millis() - starttime < ms) {
|
|
|
+ rightRing.tick();
|
|
|
+ leftRing.tick();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/* MAIN LOOP */
|
|
|
void loop() {
|
|
|
int8_t clearButtonAction;
|
|
|
boolean clearButtonState;
|
|
|
// put your main code here, to run repeatedly:
|
|
|
easterEggSongCheck(); // Sometimes we play a song
|
|
|
- prettyLEDCheck();
|
|
|
+ prettyLEDCheck(); // Sometimes we do something pretty with LEDs
|
|
|
+ //prettyRingCheck(); // Sometimes we do something pretty with the RGB LEDs
|
|
|
+
|
|
|
+ leftRing.tick();
|
|
|
+ rightRing.tick();
|
|
|
|
|
|
clearToggle.readButton(&clearButtonAction, &clearButtonState);
|
|
|
|
|
@@ -293,19 +324,24 @@ void loop() {
|
|
|
|
|
|
printClocks(leftClock, rightClock);
|
|
|
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(true); // blocking buzz so we don't do LED stuff
|
|
|
|
|
|
- /* If either coaster is open (no glass), continue on */
|
|
|
+ /* If either coaster is open (no glass), continue through the loop */
|
|
|
if (leftSwitchOpen() || rightSwitchOpen()) {
|
|
|
clearLEDs();
|
|
|
if(!leftSwitchOpen()) {
|
|
|
digitalWrite(ledPinsLeft[0], HIGH);
|
|
|
- ring_setColor(leftRing, RED);
|
|
|
- } else if(!rightSwitchOpen()) {
|
|
|
+ leftRing.init_solid(RED, 80);
|
|
|
+ } else if(leftRing.action == Solid) {
|
|
|
+ leftRing.init_idle();
|
|
|
+ }
|
|
|
+ if(!rightSwitchOpen()) {
|
|
|
digitalWrite(ledPinsRight[0], HIGH);
|
|
|
- ring_setColor(rightRing, RED);
|
|
|
+ rightRing.init_solid(RED, 80);
|
|
|
+ } else if(rightRing.action == Solid) {
|
|
|
+ rightRing.init_idle();
|
|
|
}
|
|
|
- delay(mainDelay);
|
|
|
+ mydelay(mainDelay);
|
|
|
return; /* Can't continue in main loop */
|
|
|
} else {
|
|
|
/* Both are closed, race can begin */
|
|
@@ -324,7 +360,7 @@ void loop() {
|
|
|
}
|
|
|
|
|
|
/* Rest before looping again */
|
|
|
- delay(mainDelay);
|
|
|
+ mydelay(mainDelay);
|
|
|
}
|
|
|
|
|
|
void countdown(void) {
|
|
@@ -335,10 +371,14 @@ void countdown(void) {
|
|
|
|
|
|
if(digitalRead(modePin) == HIGH) {
|
|
|
/* Drag race mode */
|
|
|
+ leftRing.init_solid(YELLOW, 80);
|
|
|
+ rightRing.init_solid(YELLOW, 80);
|
|
|
mode = 1;
|
|
|
} else {
|
|
|
/* Random delay mode */
|
|
|
setLEDs(RED, BLACK, BLACK, BLACK, YELLOW);
|
|
|
+ leftRing.init_solid(YELLOW, 80);
|
|
|
+ rightRing.init_solid(YELLOW, 80);
|
|
|
randomAdditionalDelay = random(maxDelay);
|
|
|
mode = 0;
|
|
|
}
|
|
@@ -354,17 +394,20 @@ void countdown(void) {
|
|
|
}
|
|
|
printClocks(leftClock, rightClock);
|
|
|
startsong();
|
|
|
- delay(startDelay);
|
|
|
+ mydelay(startDelay);
|
|
|
|
|
|
unsigned long start = millis();
|
|
|
while (1) {
|
|
|
+ rightRing.tick();
|
|
|
+ leftRing.tick();
|
|
|
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(false);
|
|
|
|
|
|
if (leftSwitchOpen_debounce(1) || rightSwitchOpen_debounce(1)) {
|
|
|
/* FALSE START! */
|
|
|
if (leftSwitchOpen_debounce(1)) {
|
|
|
Serial.println("FALSE START: Player Left");
|
|
|
+ leftRing.init_solid(RED, 80);
|
|
|
buzz_nonblock();
|
|
|
leftClock = 9999;
|
|
|
rightClock = 0;
|
|
@@ -382,9 +425,15 @@ void countdown(void) {
|
|
|
delay(buzzerDuration - 900); /* Rest for the remaining buzz */
|
|
|
leftSwitchOpen_debounce(1);
|
|
|
rightSwitchOpen_debounce(1); /* Get another reading just to clear things out */
|
|
|
+ leftRing.init_pulse(RED, 80, 1000);
|
|
|
+ mydelay(1000);
|
|
|
+ leftRing.init_pulse(RED, 80, 1000);
|
|
|
+ mydelay(1000);
|
|
|
+ leftRing.init_pulse(RED, 80, 1000);
|
|
|
return;
|
|
|
} else if (rightSwitchOpen_debounce(1)) {
|
|
|
Serial.println("FALSE START: Player Right");
|
|
|
+ rightRing.init_solid(RED, 80);
|
|
|
buzz_nonblock();
|
|
|
rightClock = 9999;
|
|
|
leftClock = 0;
|
|
@@ -402,6 +451,11 @@ void countdown(void) {
|
|
|
delay(buzzerDuration - 900); /* Rest for the remaining buzz */
|
|
|
leftSwitchOpen_debounce(1);
|
|
|
rightSwitchOpen_debounce(1); /* Get another reading just to clear things out */
|
|
|
+ rightRing.init_pulse(RED, 80, 1000);
|
|
|
+ mydelay(1000);
|
|
|
+ rightRing.init_pulse(RED, 80, 1000);
|
|
|
+ mydelay(1000);
|
|
|
+ rightRing.init_pulse(RED, 80, 1000);
|
|
|
return;
|
|
|
} else {
|
|
|
/* WTF? Timing issue */
|
|
@@ -417,7 +471,8 @@ void countdown(void) {
|
|
|
if (cstep != 0) {
|
|
|
Serial.println("Countdown ... 3");
|
|
|
setLEDs(RED, BLACK, BLACK, BLACK, YELLOW);
|
|
|
- beep();
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, 0, beepDuration);
|
|
|
cstep = 0;
|
|
|
}
|
|
|
continue;
|
|
@@ -425,7 +480,8 @@ void countdown(void) {
|
|
|
if (cstep != 1) {
|
|
|
Serial.println("Countdown ... 2");
|
|
|
setLEDs(RED, BLACK, BLACK, YELLOW, BLACK);
|
|
|
- beep();
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, 0, beepDuration);
|
|
|
cstep = 1;
|
|
|
}
|
|
|
continue;
|
|
@@ -433,13 +489,17 @@ void countdown(void) {
|
|
|
if (cstep != 2) {
|
|
|
Serial.println("Countdown ... 1");
|
|
|
setLEDs(RED, BLACK, YELLOW, BLACK, BLACK);
|
|
|
- beep();
|
|
|
+ rightRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, beepFrequency, beepDuration);
|
|
|
+ leftRing.init_pulse_and_beep(YELLOW, 80, lightDelay, buzzerPin, 0, beepDuration);
|
|
|
cstep = 2;
|
|
|
}
|
|
|
continue;
|
|
|
case 3:
|
|
|
Serial.println("Countdown ... GO!!!!!!!!");
|
|
|
setLEDs(BLACK, GREEN, BLACK, BLACK, BLACK);
|
|
|
+ leftRing.init_solid(GREEN, 80);
|
|
|
+ rightRing.init_solid(GREEN, 80);
|
|
|
+ mydelay(lightDelay/2);
|
|
|
longbeep();
|
|
|
race_loop();
|
|
|
return;
|
|
@@ -449,12 +509,14 @@ void countdown(void) {
|
|
|
if(millis() > (start + startDelay + randomAdditionalDelay)) {
|
|
|
Serial.println("Random delay met... GO!!!!!!!!");
|
|
|
setLEDs(BLACK, GREEN, BLACK, BLACK, BLACK);
|
|
|
+ leftRing.init_solid(GREEN, 80);
|
|
|
+ rightRing.init_solid(GREEN, 80);
|
|
|
longbeep();
|
|
|
race_loop();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- delay(countdownDelay); /* Make the loop less aggressive */
|
|
|
+ mydelay(countdownDelay); /* Make the loop less aggressive */
|
|
|
}
|
|
|
Serial.println("Should never get here...");
|
|
|
}
|
|
@@ -472,12 +534,12 @@ void race_loop(void) {
|
|
|
timerLeft = timerRight = 0;
|
|
|
|
|
|
/* determine handicap settings */
|
|
|
- if(digitalRead(difficultyLeftPin) == 0) {
|
|
|
- handicap_left = true;
|
|
|
- }
|
|
|
- if(digitalRead(difficultyRightPin) == 0) {
|
|
|
- handicap_right = true;
|
|
|
- }
|
|
|
+ //if(digitalRead(difficultyLeftPin) == 0) {
|
|
|
+ // handicap_left = true;
|
|
|
+ //}
|
|
|
+ //if(digitalRead(difficultyRightPin) == 0) {
|
|
|
+ // handicap_right = true;
|
|
|
+ //}
|
|
|
|
|
|
/* Record whether the racer picked up his/her cup */
|
|
|
int leftStarted = 0;
|
|
@@ -517,30 +579,34 @@ void race_loop(void) {
|
|
|
Serial.print("Left player finished at ");
|
|
|
Serial.println(millis() - start);
|
|
|
timerLeft = (millis() - start) / 10;
|
|
|
- if(handicap_left) {
|
|
|
- /* Handicapped player */
|
|
|
- timerLeft = timerLeft - (timerLeft >> 2);
|
|
|
- }
|
|
|
+ //if(handicap_left) {
|
|
|
+ // /* Handicapped player */
|
|
|
+ // timerLeft = timerLeft - (timerLeft >> 2);
|
|
|
+ //}
|
|
|
+ leftRing.init_solid(ORANGE, 80);
|
|
|
beep_nonblock();
|
|
|
} else if (leftOpen && !leftStarted) {
|
|
|
Serial.print("Left cup lifted at ");
|
|
|
Serial.println(millis() - start);
|
|
|
leftStarted = 1;
|
|
|
+ leftRing.init_solid(YELLOW, 80);
|
|
|
}
|
|
|
if (!rightOpen && rightStarted && !timerRight) {
|
|
|
/* Finished */
|
|
|
Serial.print("Right player finished at ");
|
|
|
Serial.println(millis() - start);
|
|
|
timerRight = (millis() - start) / 10;
|
|
|
- if(handicap_right) {
|
|
|
- /* Handicapped player */
|
|
|
- timerRight = timerRight - (timerRight >> 2);
|
|
|
- }
|
|
|
+ //if(handicap_right) {
|
|
|
+ // /* Handicapped player */
|
|
|
+ // timerRight = timerRight - (timerRight >> 2);
|
|
|
+ //}
|
|
|
+ rightRing.init_solid(ORANGE, 80);
|
|
|
beep_nonblock();
|
|
|
} else if (rightOpen && !rightStarted) {
|
|
|
Serial.print("Right cup lifted at ");
|
|
|
Serial.println(millis() - start);
|
|
|
rightStarted = 1;
|
|
|
+ rightRing.init_solid(YELLOW, 80);
|
|
|
}
|
|
|
|
|
|
/* Check for renegers
|
|
@@ -579,19 +645,19 @@ void race_loop(void) {
|
|
|
leftClock = timerLeft;
|
|
|
} else {
|
|
|
leftClock = (millis() - start) / 10;
|
|
|
- if(handicap_left) {
|
|
|
- /* Handicapped player */
|
|
|
- leftClock = leftClock - (leftClock >> 2);
|
|
|
- }
|
|
|
+ //if(handicap_left) {
|
|
|
+ // /* Handicapped player */
|
|
|
+ // leftClock = leftClock - (leftClock >> 2);
|
|
|
+ //}
|
|
|
}
|
|
|
if (timerRight) {
|
|
|
rightClock = timerRight;
|
|
|
} else {
|
|
|
rightClock = (millis() - start) / 10;
|
|
|
- if(handicap_right) {
|
|
|
- /* Handicapped player */
|
|
|
- rightClock = rightClock - (rightClock >> 2);
|
|
|
- }
|
|
|
+ //if(handicap_right) {
|
|
|
+ // /* Handicapped player */
|
|
|
+ // rightClock = rightClock - (rightClock >> 2);
|
|
|
+ //}
|
|
|
}
|
|
|
/* Print the clocks */
|
|
|
printClocks(leftClock, rightClock);
|
|
@@ -600,6 +666,8 @@ void race_loop(void) {
|
|
|
ledsToRed();
|
|
|
if(timerRight < timerLeft) {
|
|
|
Serial.println("Right player WINS!");
|
|
|
+ rightRing.init_solid(GREEN, 80);
|
|
|
+ leftRing.init_solid(RED, 80);
|
|
|
for(int i = 0; i < 3; i++) {
|
|
|
rightDisplay.listen();
|
|
|
rightDisplay.write(0x7A);
|
|
@@ -612,6 +680,8 @@ void race_loop(void) {
|
|
|
delay(150);
|
|
|
}
|
|
|
} else if(timerLeft < timerRight) {
|
|
|
+ leftRing.init_solid(GREEN, 80);
|
|
|
+ rightRing.init_solid(RED, 80);
|
|
|
for(int i = 0; i < 3; i++) {
|
|
|
leftDisplay.listen();
|
|
|
leftDisplay.write(0x7A);
|
|
@@ -630,7 +700,7 @@ void race_loop(void) {
|
|
|
playWinner();
|
|
|
/* Wait until start buttons are no longer pressed */
|
|
|
while(startButtonPressed()) {
|
|
|
- delay(100);
|
|
|
+ mydelay(100);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
@@ -640,9 +710,13 @@ void race_loop(void) {
|
|
|
}
|
|
|
|
|
|
/* Beep and buzz if those toggles are pressed */
|
|
|
-void shouldwebuzz() {
|
|
|
+void shouldwebuzz(bool block) {
|
|
|
if(digitalRead(buzzPin) == LOW) {
|
|
|
- buzz_nonblock();
|
|
|
+ if(block) {
|
|
|
+ buzz();
|
|
|
+ } else {
|
|
|
+ buzz_nonblock();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -673,12 +747,13 @@ int leftSwitchOpen() {
|
|
|
}
|
|
|
|
|
|
int leftSwitchOpen_debounce(int silent) {
|
|
|
+ return leftSwitchOpen(silent);
|
|
|
+
|
|
|
+ // Temporarily just ignoring everything
|
|
|
/* Not a standard debounce method. We're going to keep the last 16 values
|
|
|
* and majority rules.
|
|
|
*/
|
|
|
- return leftSwitchOpen(silent);
|
|
|
-
|
|
|
- // We are ignorign all of this now
|
|
|
+
|
|
|
static int results[16] = {0,0,0,0,0,
|
|
|
0,0,0,0,0,
|
|
|
0,0,0,0,0,0};
|
|
@@ -720,11 +795,11 @@ int rightSwitchOpen() {
|
|
|
}
|
|
|
|
|
|
int rightSwitchOpen_debounce(int silent) {
|
|
|
+ return rightSwitchOpen(silent);
|
|
|
+
|
|
|
/* Not a standard debounce method. We're going to keep the last 16 values
|
|
|
* and majority rules.
|
|
|
*/
|
|
|
- return rightSwitchOpen(silent);
|
|
|
-
|
|
|
// we are ignoring all this
|
|
|
static int results[16] = {0,0,0,0,0,
|
|
|
0,0,0,0,0,
|
|
@@ -813,7 +888,8 @@ void printClocks(unsigned long leftValue, unsigned long rightValue) {
|
|
|
|
|
|
/* LED Functions */
|
|
|
void ledsToRed() {
|
|
|
- ws2812_ledsToRed();
|
|
|
+ leftRing.init_solid(RED, 80);
|
|
|
+ rightRing.init_solid(RED, 80);
|
|
|
digitalWrite(ledPinsLeft[0], HIGH);
|
|
|
digitalWrite(ledPinsRight[0], HIGH);
|
|
|
for(int i=1; i<5; i++) {
|
|
@@ -823,17 +899,16 @@ void ledsToRed() {
|
|
|
}
|
|
|
|
|
|
// Sets red light on.
|
|
|
-void ws2812_ledsToRed() {
|
|
|
- clearLEDs();
|
|
|
- rightRing.setPixelColor(0, RED);
|
|
|
- leftRing.setPixelColor(0, RED);
|
|
|
- rightRing.show();
|
|
|
- leftRing.show();
|
|
|
-}
|
|
|
+//void ws2812_ledsToRed() {
|
|
|
+// clearLEDs();
|
|
|
+// rightRing.setPixelColor(0, RED);
|
|
|
+// leftRing.setPixelColor(0, RED);
|
|
|
+// rightRing.show();
|
|
|
+// leftRing.show();
|
|
|
+//}
|
|
|
|
|
|
/* Clears all LEDs (for WS2812, except the top one) */
|
|
|
void clearLEDs() {
|
|
|
- ws2812_clearLEDs();
|
|
|
for(int i = 0; i < 5; i++) {
|
|
|
digitalWrite(ledPinsLeft[i], LOW);
|
|
|
digitalWrite(ledPinsRight[i], LOW);
|
|
@@ -985,7 +1060,7 @@ void ws2812_setLEDs(unsigned long redlight,
|
|
|
}
|
|
|
|
|
|
void prettyLEDCheck() {
|
|
|
- /* Lets see if we should play a song */
|
|
|
+ /* Lets see if we should do pretty things with the regular LEDs */
|
|
|
if ( (millis() - lastPrettyLEDCheck) > (prettyLEDFrequency * 1000) ) {
|
|
|
lastPrettyLEDCheck = millis();
|
|
|
if ( (random(0, 1000) < long(prettyLEDProbability * 1000.0)) ) {
|
|
@@ -998,24 +1073,34 @@ void prettyLEDCheck() {
|
|
|
}
|
|
|
|
|
|
void prettyLED() {
|
|
|
- /* if using the ws2812's, you may want to turn this back on
|
|
|
- ws2812_prettyLED();
|
|
|
- */
|
|
|
- if(random(0, 1000) < 500) {
|
|
|
- prettyCircleLED();
|
|
|
- prettyCircleLED();
|
|
|
-// prettyCircleLED();
|
|
|
+ if(random(0, 2) == 0) {
|
|
|
+ // use the classic LEDs
|
|
|
+ if(random(0, 1000) < 500) {
|
|
|
+ prettyCircleLED();
|
|
|
+ prettyCircleLED();
|
|
|
+ // prettyCircleLED();
|
|
|
+ } else {
|
|
|
+ prettyBounceLED();
|
|
|
+ prettyBounceLED();
|
|
|
+ prettyBounceLED();
|
|
|
+ }
|
|
|
} else {
|
|
|
- prettyBounceLED();
|
|
|
- prettyBounceLED();
|
|
|
- prettyBounceLED();
|
|
|
+ // Use the RGB LEDs
|
|
|
+ if(random(0, 10) != 0) {
|
|
|
+ // 90% chance that both rings do the same thing
|
|
|
+ int draw = leftRing.random_event();
|
|
|
+ rightRing.random_event(draw);
|
|
|
+ } else {
|
|
|
+ leftRing.random_event();
|
|
|
+ rightRing.random_event();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void prettyCircleLED() {
|
|
|
clearLEDs();
|
|
|
for(int i = 4; i >= 0; i--) {
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(true);
|
|
|
Serial.print("Pin: ");
|
|
|
Serial.println(i);
|
|
|
digitalWrite(ledPinsLeft[i], HIGH);
|
|
@@ -1023,7 +1108,7 @@ void prettyCircleLED() {
|
|
|
digitalWrite(ledPinsLeft[i], LOW);
|
|
|
}
|
|
|
for(int i = 0; i < 5; i++) {
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(true);
|
|
|
Serial.print("Pin: ");
|
|
|
Serial.println(i);
|
|
|
digitalWrite(ledPinsRight[i], HIGH);
|
|
@@ -1035,7 +1120,7 @@ void prettyCircleLED() {
|
|
|
void prettyBounceLED() {
|
|
|
clearLEDs();
|
|
|
for(int i = 4; i >= 0; i--) {
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(true);
|
|
|
digitalWrite(ledPinsLeft[i], HIGH);
|
|
|
digitalWrite(ledPinsRight[i], HIGH);
|
|
|
delay(100);
|
|
@@ -1043,7 +1128,7 @@ void prettyBounceLED() {
|
|
|
digitalWrite(ledPinsRight[i], LOW);
|
|
|
}
|
|
|
for(int i = 1; i < 5; i++) {
|
|
|
- shouldwebuzz();
|
|
|
+ shouldwebuzz(true);
|
|
|
digitalWrite(ledPinsLeft[i], HIGH);
|
|
|
digitalWrite(ledPinsRight[i], HIGH);
|
|
|
delay(100);
|
|
@@ -1052,6 +1137,27 @@ void prettyBounceLED() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void prettyRingCheck() {
|
|
|
+ // this doesn't work
|
|
|
+ static unsigned long last_random_check = millis();
|
|
|
+
|
|
|
+ if(leftRing.action == Idle && rightRing.action == Idle) {
|
|
|
+ if(millis() - last_random_check > 1000) { // only check every 10 seconds
|
|
|
+ if(random(0, 20) == 0) { // do we do anything?
|
|
|
+ if(random(0, 10) != 0) {
|
|
|
+ // 90% chance that both rings do the same thing
|
|
|
+ int draw = leftRing.random_event();
|
|
|
+ rightRing.random_event(draw);
|
|
|
+ } else {
|
|
|
+ leftRing.random_event();
|
|
|
+ rightRing.random_event();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ last_random_check = millis();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void ws2812_prettyLED() {
|
|
|
/* Do something interesting */
|
|
@@ -1164,10 +1270,10 @@ int frequency(char note)
|
|
|
void playWinner() {
|
|
|
/* TODO: Ideally, this is "Enjoy MonkeyBOX", but anything will do */
|
|
|
/* Also, ideally won't block */
|
|
|
- if(random(0, 10) < 9) {
|
|
|
- playsong();
|
|
|
- } else {
|
|
|
+ if(random(0, 10) == 0) {
|
|
|
playsong2();
|
|
|
+ } else {
|
|
|
+ playsong();
|
|
|
}
|
|
|
Serial.println("Insert winner music here.");
|
|
|
}
|