|
@@ -0,0 +1,147 @@
|
|
|
+
|
|
|
+#include <SoftwareSerial.h>
|
|
|
+#include <WS2812_Definitions.h>
|
|
|
+#include <eRCaGuy_ButtonReader.h>
|
|
|
+#include <BackgroundRingClass.h>
|
|
|
+
|
|
|
+const int LED_COUNT = 24;
|
|
|
+const int MAXBRIGHTNESS = 80;
|
|
|
+
|
|
|
+const int leftFSRSimPin = A7;
|
|
|
+const int rightFSRSimPin = A0;
|
|
|
+
|
|
|
+/* Start Button */
|
|
|
+const int leftReadyButtonPin = 13;
|
|
|
+const int rightReadyButtonPin = 8;
|
|
|
+
|
|
|
+/* WS2812 Christmas Tree Setup:
|
|
|
+ Two strips of 6 LEDs connected to 5V and Ground, plus the signal pin
|
|
|
+*/
|
|
|
+const int ledPinRight = 12;
|
|
|
+const int ledPinLeft = 11;
|
|
|
+
|
|
|
+const int randomPin = A5;
|
|
|
+
|
|
|
+BackgroundRingClass rightRing = BackgroundRingClass(LED_COUNT, ledPinRight);
|
|
|
+BackgroundRingClass leftRing = BackgroundRingClass(LED_COUNT, ledPinLeft);
|
|
|
+
|
|
|
+eRCaGuy_ButtonReader leftReadyButton = eRCaGuy_ButtonReader(leftReadyButtonPin, 25);
|
|
|
+eRCaGuy_ButtonReader rightReadyButton = eRCaGuy_ButtonReader(rightReadyButtonPin, 25);
|
|
|
+eRCaGuy_ButtonReader leftFSRButton = eRCaGuy_ButtonReader(leftFSRSimPin, 25);
|
|
|
+eRCaGuy_ButtonReader rightFSRButton = eRCaGuy_ButtonReader(rightFSRSimPin, 25);
|
|
|
+
|
|
|
+
|
|
|
+void setup() {
|
|
|
+ // put your setup code here, to run once:
|
|
|
+ Serial.begin(115200); // Serial used for logging
|
|
|
+
|
|
|
+ randomSeed(analogRead(randomPin));
|
|
|
+
|
|
|
+ /* WS2812 LED Setup */
|
|
|
+ //rightRing.begin();
|
|
|
+ //leftRing.begin();
|
|
|
+
|
|
|
+ pinMode(leftReadyButtonPin, INPUT_PULLUP);
|
|
|
+ pinMode(rightReadyButtonPin, INPUT_PULLUP);
|
|
|
+ pinMode(leftFSRSimPin, INPUT_PULLUP);
|
|
|
+ pinMode(rightFSRSimPin, INPUT_PULLUP);
|
|
|
+
|
|
|
+ Serial.println("Testing Solids");
|
|
|
+ rightRing.init_solid(DARKRED, MAXBRIGHTNESS);
|
|
|
+ leftRing.init_solid(DARKGREEN, MAXBRIGHTNESS);
|
|
|
+ delay(1000);
|
|
|
+ leftRing.init_idle();
|
|
|
+ rightRing.init_idle();
|
|
|
+ Serial.println("Begin.");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void loop() {
|
|
|
+ static unsigned long last_random_check = millis();
|
|
|
+
|
|
|
+ rightRing.tick();
|
|
|
+ leftRing.tick();
|
|
|
+
|
|
|
+ if(button_pressed(rightFSRButton)) {
|
|
|
+ Serial.println("Right button pressed. Switching.");
|
|
|
+ //rightRing.init_pulse(random(0, 0xFFFFFF), 255, 2000);
|
|
|
+ //rightRing.init_pulse(DARKRED, MAXBRIGHTNESS, 2000);
|
|
|
+ //rightRing.init_spin(DARKRED, DARKGREEN);
|
|
|
+ //rightRing.init_flip(DARKRED, DARKGREEN);
|
|
|
+ //rightRing.init_slowroll(DARKRED, DARKGREEN);
|
|
|
+ rightRing.random_event();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(button_pressed(leftFSRButton)) {
|
|
|
+ Serial.println("Right button pressed. Switching.");
|
|
|
+ //leftRing.init_pulse(random(0, 0xFFFFFF), 255, 2000);
|
|
|
+ //leftRing.init_pulse(DARKGREEN, MAXBRIGHTNESS, 2000);
|
|
|
+ //leftRing.init_spin(DARKGREEN, DARKRED);
|
|
|
+ //leftRing.init_flip(DARKGREEN, DARKRED);
|
|
|
+ //leftRing.init_slowroll(DARKGREEN, DARKRED);
|
|
|
+ leftRing.random_event();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(leftRing.action == Idle && rightRing.action == Idle) {
|
|
|
+ if(millis() - last_random_check > 1000) { // only check every 10 seconds
|
|
|
+ if(random(0, 10) == 0) {
|
|
|
+ int draw = leftRing.random_event();
|
|
|
+ rightRing.random_event(draw); // synchronized
|
|
|
+ }
|
|
|
+ last_random_check = millis();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ last_random_check = millis(); // don't count time in an action
|
|
|
+ }
|
|
|
+
|
|
|
+ //test_solids();
|
|
|
+ //test_pulses();
|
|
|
+ //test_random_pulses();
|
|
|
+}
|
|
|
+
|
|
|
+bool button_pressed(eRCaGuy_ButtonReader& button)
|
|
|
+{
|
|
|
+ int8_t buttonaction;
|
|
|
+ boolean buttonstate;
|
|
|
+
|
|
|
+ button.readButton(&buttonaction, &buttonstate);
|
|
|
+ return buttonaction == 1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void test_pulses() {
|
|
|
+ if(rightRing.action == Idle) {
|
|
|
+ Serial.println("Changing right");
|
|
|
+ rightRing.init_pulse(DARKGREEN, MAXBRIGHTNESS, 2000);
|
|
|
+ }
|
|
|
+ if(leftRing.action == Idle) {
|
|
|
+ Serial.println("Changing left");
|
|
|
+ leftRing.init_pulse(DARKGREEN, MAXBRIGHTNESS, 2000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void test_random_pulses() {
|
|
|
+ if(rightRing.action == Idle) {
|
|
|
+ Serial.println("Changing right");
|
|
|
+ rightRing.init_pulse(random(0, 0xFFFFFF), MAXBRIGHTNESS, 2000);
|
|
|
+ }
|
|
|
+ if(leftRing.action == Idle) {
|
|
|
+ Serial.println("Changing left");
|
|
|
+ leftRing.init_pulse(random(0, 0xFFFFFF), MAXBRIGHTNESS, 2000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void test_random_solids() {
|
|
|
+ if(rightRing.action == Idle) {
|
|
|
+ Serial.println("Changing right");
|
|
|
+ rightRing.init_solid(random(0, 0xFFFFFF), MAXBRIGHTNESS);
|
|
|
+ }
|
|
|
+ if(leftRing.action == Idle) {
|
|
|
+ Serial.println("Changing left");
|
|
|
+ leftRing.init_solid(random(0, 0xFFFFFF), MAXBRIGHTNESS);
|
|
|
+ }
|
|
|
+ delay(500);
|
|
|
+ leftRing.init_idle();
|
|
|
+ rightRing.init_idle();
|
|
|
+}
|