Browse Source

Shipped version on 2025-02-14

Fred Damstra (Macbook 2015) 5 months ago
parent
commit
47a192f68c
2 changed files with 211 additions and 259 deletions
  1. 211 105
      CiderRacer2600.ino
  2. 0 154
      WS2812_Definitions.h

+ 211 - 105
CiderRacer2600.ino

@@ -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.");
 }

+ 0 - 154
WS2812_Definitions.h

@@ -1,154 +0,0 @@
-/* 
-  Bunches of definitions for the WS2812 Breakout Board example code
-  
-*/ 
-
-// These are for the cascade function
-#define TOP_DOWN 0
-#define DOWN_TOP 1
-
-/* A world of colors to set your LED to
-  Standard HTML Color Codes sorted by Hex Value
-    to see the colors in action, check out:
-   http://www.w3schools.com/html/html_colorvalues.asp */
-   
-#define BLACK			0x000000
-#define NAVY			0x000080
-#define DARKBLUE		0x00008B
-#define MEDIUMBLUE		0x0000CD
-#define BLUE			0x0000FF
-#define DARKGREEN		0x006400
-#define GREEN			0x008000
-#define TEAL			0x008080
-#define DARKCYAN		0x008B8B
-#define DEEPSKYBLUE		0x00BFFF
-#define DARKTURQUOISE		0x00CED1
-#define MEDIUMSPRINGGREEN	0x00FA9A
-#define LIME			0x00FF00
-#define SPRINGGREEN		0x00FF7F
-#define AQUA			0x00FFFF
-#define CYAN			0x00FFFF
-#define MIDNIGHTBLUE		0x191970
-#define DODGERBLUE		0x1E90FF
-#define LIGHTSEAGREEN		0x20B2AA
-#define FORESTGREEN		0x228B22
-#define SEAGREEN		0x2E8B57
-#define DARKSLATEGRAY		0x2F4F4F
-#define LIMEGREEN		0x32CD32
-#define MEDIUMSEAGREEN		0x3CB371
-#define TURQUOISE		0x40E0D0
-#define ROYALBLUE		0x4169E1
-#define STEELBLUE		0x4682B4
-#define DARKSLATEBLUE		0x483D8B
-#define MEDIUMTURQUOISE		0x48D1CC
-#define INDIGO 			0x4B0082
-#define DARKOLIVEGREEN		0x556B2F
-#define CADETBLUE		0x5F9EA0
-#define CORNFLOWERBLUE		0x6495ED
-#define MEDIUMAQUAMARINE	0x66CDAA
-#define DIMGRAY			0x696969
-#define SLATEBLUE		0x6A5ACD
-#define OLIVEDRAB		0x6B8E23
-#define SLATEGRAY		0x708090
-#define LIGHTSLATEGRAY		0x778899
-#define MEDIUMSLATEBLUE		0x7B68EE
-#define LAWNGREEN		0x7CFC00
-#define CHARTREUSE		0x7FFF00
-#define AQUAMARINE		0x7FFFD4
-#define MAROON			0x800000
-#define PURPLE			0x800080
-#define OLIVE			0x808000
-#define GRAY			0x808080
-#define SKYBLUE			0x87CEEB
-#define LIGHTSKYBLUE		0x87CEFA
-#define BLUEVIOLET		0x8A2BE2
-#define DARKRED			0x8B0000
-#define DARKMAGENTA		0x8B008B
-#define SADDLEBROWN		0x8B4513
-#define DARKSEAGREEN		0x8FBC8F
-#define LIGHTGREEN		0x90EE90
-#define MEDIUMPURPLE		0x9370DB
-#define DARKVIOLET		0x9400D3
-#define PALEGREEN		0x98FB98
-#define DARKORCHID		0x9932CC
-#define YELLOWGREEN		0x9ACD32
-#define SIENNA			0xA0522D
-#define BROWN			0xA52A2A
-#define DARKGRAY		0xA9A9A9
-#define LIGHTBLUE		0xADD8E6
-#define GREENYELLOW		0xADFF2F
-#define PALETURQUOISE	        0xAFEEEE
-#define LIGHTSTEELBLUE		0xB0C4DE
-#define POWDERBLUE		0xB0E0E6
-#define FIREBRICK		0xB22222
-#define DARKGOLDENROD		0xB8860B
-#define MEDIUMORCHID		0xBA55D3
-#define ROSYBROWN		0xBC8F8F
-#define DARKKHAKI		0xBDB76B
-#define SILVER			0xC0C0C0
-#define MEDIUMVIOLETRED	        0xC71585
-#define INDIANRED 		0xCD5C5C
-#define PERU			0xCD853F
-#define CHOCOLATE		0xD2691E
-#define TAN			0xD2B48C
-#define LIGHTGRAY		0xD3D3D3
-#define THISTLE			0xD8BFD8
-#define ORCHID			0xDA70D6
-#define GOLDENROD		0xDAA520
-#define PALEVIOLETRED		0xDB7093
-#define CRIMSON			0xDC143C
-#define GAINSBORO		0xDCDCDC
-#define PLUM			0xDDA0DD
-#define BURLYWOOD		0xDEB887
-#define LIGHTCYAN		0xE0FFFF
-#define LAVENDER		0xE6E6FA
-#define DARKSALMON		0xE9967A
-#define VIOLET			0xEE82EE
-#define PALEGOLDENROD		0xEEE8AA
-#define LIGHTCORAL		0xF08080
-#define KHAKI			0xF0E68C
-#define ALICEBLUE		0xF0F8FF
-#define HONEYDEW		0xF0FFF0
-#define AZURE			0xF0FFFF
-#define SANDYBROWN		0xF4A460
-#define WHEAT			0xF5DEB3
-#define BEIGE			0xF5F5DC
-#define WHITESMOKE		0xF5F5F5
-#define MINTCREAM		0xF5FFFA
-#define GHOSTWHITE		0xF8F8FF
-#define SALMON			0xFA8072
-#define ANTIQUEWHITE		0xFAEBD7
-#define LINEN			0xFAF0E6
-#define LIGHTGOLDENRODYELLOW	0xFAFAD2
-#define OLDLACE			0xFDF5E6
-#define RED			0xFF0000
-#define FUCHSIA			0xFF00FF
-#define MAGENTA			0xFF00FF
-#define DEEPPINK		0xFF1493
-#define ORANGERED		0xFF4500
-#define TOMATO			0xFF6347
-#define HOTPINK			0xFF69B4
-#define CORAL			0xFF7F50
-#define DARKORANGE		0xFF8C00
-#define LIGHTSALMON		0xFFA07A
-#define ORANGE			0xFFA500
-#define LIGHTPINK		0xFFB6C1
-#define REGPINK			0xFFC0CB // "PINK" conflicts with builtin
-#define GOLD			0xFFD700
-#define PEACHPUFF		0xFFDAB9
-#define NAVAJOWHITE		0xFFDEAD
-#define MOCCASIN		0xFFE4B5
-#define BISQUE			0xFFE4C4
-#define MISTYROSE		0xFFE4E1
-#define BLANCHEDALMOND		0xFFEBCD
-#define PAPAYAWHIP		0xFFEFD5
-#define LAVENDERBLUSH		0xFFF0F5
-#define SEASHELL		0xFFF5EE
-#define CORNSILK		0xFFF8DC
-#define LEMONCHIFFON		0xFFFACD
-#define FLORALWHITE		0xFFFAF0
-#define SNOW			0xFFFAFA
-#define YELLOW			0xFFFF00
-#define LIGHTYELLOW		0xFFFFE0
-#define IVORY			0xFFFFF0
-#define WHITE			0xFFFFFF