diff --git a/ProtonPack.ino b/ProtonPack.ino index 9038c82..93247af 100644 --- a/ProtonPack.ino +++ b/ProtonPack.ino @@ -10,26 +10,44 @@ #include "Synchrotron.h" // Music Player -#define MUSIC_CS 7 -#define MUSIC_DATA 6 -#define MUSIC_CARDCS 4 -#define MUSIC_REQ 3 +#define MUSIC_MCS 7 +#define MUSIC_DCS 6 +#define MUSIC_CCS 4 +#define MUSIC_DRQ 0 // Cut trace on board and wire to 0, so you can use 3 for SPI MusicPlayer *music; +// LED output scaling +#define brightness 255 + // Synchrotron #define SYNC1_NPIXELS 24 #define SYNC1_DATA 5 Synchrotron *sync1; +// Neutrona Wand +#define WAND1_NPIXELS 14 +#define WAND1_DATA 9 +Synchrotron *wand1; + +// Displays +Adafruit_7segment disp1; +Adafruit_7segment disp2; + // Debug LED #define DEBUG 13 // Inputs #define TRIGGER 8 +#define POT1 A0 // global time counter unsigned long jiffies = 0; +// 6 seems to be about what my overly-critical brain needs to buffer out +// any delays caused by NMI sections of music player code so that they're unnoticeable +#define MILLIS_PER_JIFFY 6 + + void setup() { randomSeed(analogRead(12)); @@ -40,10 +58,20 @@ void setup() { pinMode(DEBUG, OUTPUT); // music player, this sets up SPI for us - music = new MusicPlayer(MUSIC_CS, MUSIC_DATA, MUSIC_REQ, MUSIC_CARDCS); + music = new MusicPlayer(MUSIC_MCS, MUSIC_DCS, MUSIC_DRQ, MUSIC_CCS); // synchrotron sync1 = new Synchrotron(SYNC1_NPIXELS, SYNC1_DATA); + + // nuetrona wand + wand1 = new Synchrotron(WAND1_NPIXELS, WAND1_DATA); + + // 7segment displays + disp1 = Adafruit_7segment(); + disp1.begin(0x70); + + disp2 = Adafruit_7segment(); + disp2.begin(0x71); } @@ -56,39 +84,39 @@ void flashDebug() { void loop() { static int state = 0; - // 6 seems to be about what my overly-critical brain needs to buffer out - // any music player delays so that they're unnoticeable - unsigned long new_jiffies = millis() / 6; + static float disp2val = 40.83; + unsigned long new_jiffies = millis() / MILLIS_PER_JIFFY; boolean trigger = ! digitalRead(TRIGGER); music->poll(jiffies); switch (state) { - case 0: - if (trigger && music->startPlayingFile("track001.mp3")) { - state = 1; - sync1->charge(); + case 0: // move to steady state + sync1->transition(400, 12, brightness, 0, 0); + wand1->transition(400, 24, brightness, 0, 0); + state = 10; + break; + case 10: // waiting for charge button + if (trigger && sync1->transitioned() && music->startPlayingFile("track001.mp3")) { + state = 20; + sync1->transition(700, 2, brightness, brightness/8, 0); + wand1->transition(700, 10, brightness, brightness/8, 0); } break; - case 1: - if (! music->isPlaying()) { - state = 3; + case 20: // charge button pressed + if (sync1->transitioned()) { + state = 30; } break; - case 3: - if (trigger && music->startPlayingFile("track003.mp3")) { - state = 4; - sync1->fire(); + case 30: // waiting for fire button + if (trigger && music->startPlayingFile("nutrona.mp3")) { + state = 40; + sync1->transition(40, 1, brightness/8, brightness/4, brightness/2); + wand1->transition(40, 5, brightness/6, brightness/2, brightness/6); } break; - case 4: + case 40: // fire button pressed if (! trigger && music->startPlayingFile("track002.mp3")) { - state = 5; - sync1->discharge(); - } - break; - case 5: - if (! music->isPlaying()) { state = 0; } break; @@ -97,6 +125,17 @@ void loop() { if (new_jiffies > jiffies) { jiffies = new_jiffies; sync1->tick(jiffies); + wand1->tick(jiffies); + + if (jiffies % 10 == 0) { + // This is expensive + disp1.printFloat(5198 * sync1->speed()); + disp1.writeDisplay(); + + disp2val = analogRead(POT1) / 10.0; + disp2.printFloat(disp2val, 1); + disp2.writeDisplay(); + } flashDebug(); } } diff --git a/Synchrotron.cpp b/Synchrotron.cpp index 774226b..bafb98a 100644 --- a/Synchrotron.cpp +++ b/Synchrotron.cpp @@ -39,12 +39,22 @@ Synchrotron::transition(int duration, int final_tickrate, byte final_r, byte fin initial_b = b; } +bool +Synchrotron::transitioned() { + return (transition_elapsed >= transition_length); +} + +float +Synchrotron::speed() { + return 1 / ftickrate; +} + Synchrotron::standby() { transition(400, 12, brightness, 0, 0); } Synchrotron::charge() { - transition(400, 2, brightness, brightness/8, 0); + transition(700, 2, brightness, brightness/8, 0); } Synchrotron::fire() { @@ -75,10 +85,11 @@ Synchrotron::tick(unsigned long jiffies) { } if (transition_length > transition_elapsed) { - tickrate = initial_tickrate + (dtickrate * transition_elapsed); + transition_elapsed += 1; + ftickrate = initial_tickrate + (dtickrate * transition_elapsed); + tickrate = ftickrate; r = initial_r + (dr * transition_elapsed); g = initial_g + (dg * transition_elapsed); b = initial_b + (db * transition_elapsed); - transition_elapsed += 1; } } diff --git a/Synchrotron.h b/Synchrotron.h index c36cae7..06e07b4 100644 --- a/Synchrotron.h +++ b/Synchrotron.h @@ -14,9 +14,12 @@ class Synchrotron { int transition_length, transition_elapsed; int initial_tickrate, initial_r, initial_g, initial_b; float dtickrate, dr, dg, db; + float ftickrate; public: Synchrotron(uint16_t n, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800); transition(int duration, int final_tickrate, byte final_r, byte final_g, byte final_b); + bool transitioned(); + float speed(); standby(); charge(); fire(); diff --git a/nutrona.mp3 b/nutrona.mp3 new file mode 100644 index 0000000..4ca0148 Binary files /dev/null and b/nutrona.mp3 differ diff --git a/radlove.svg b/radlove.svg new file mode 100644 index 0000000..4291a42 --- /dev/null +++ b/radlove.svg @@ -0,0 +1,119 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + +