diff --git a/MusicPlayer.cpp b/MusicPlayer.cpp index 63092bb..9d3c40d 100644 --- a/MusicPlayer.cpp +++ b/MusicPlayer.cpp @@ -28,6 +28,12 @@ MusicPlayer::startPlayingFile(const char *trackname) return musicPlayer->startPlayingFile(trackname); } +boolean +MusicPlayer::isPlaying() +{ + return musicPlayer->playingMusic; +} + void MusicPlayer::stopPlaying() { diff --git a/MusicPlayer.h b/MusicPlayer.h index e7e652b..528edb0 100644 --- a/MusicPlayer.h +++ b/MusicPlayer.h @@ -9,6 +9,7 @@ public: MusicPlayer(int8_t cs, int8_t dcs, int8_t dreq, int8_t cardcs); boolean startPlayingFile(const char *trackname); void setVolume(uint8_t left, uint8_t right); + boolean isPlaying(); void stopPlaying(); void poll(unsigned long jiffies); // Call this once per loop() }; diff --git a/ProtonPack.ino b/ProtonPack.ino index cc4c9bf..5c4b2d6 100644 --- a/ProtonPack.ino +++ b/ProtonPack.ino @@ -25,7 +25,7 @@ Synchrotron *sync1; #define DEBUG 13 // Inputs -#define TRIGGER 9 +#define TRIGGER 8 // global time counter unsigned long jiffies = 0; @@ -63,18 +63,34 @@ void loop() { music->poll(jiffies); - if (state == 0) { - if (new_jiffies > jiffies) { - if (trigger) { + switch (state) { + case 0: + if (trigger) { + if (music->startPlayingFile("track001.mp3")) { state = 1; - music->startPlayingFile("track001.mp3"); sync1->charge(); } - - jiffies = new_jiffies; - sync1->tick(jiffies); - flashDebug(); } + break; + case 1: + if (! music->isPlaying()) { + if (music->startPlayingFile("track002.mp3")) { + state = 4; + sync1->standby(); + } + } + break; + case 4: + if (! music->isPlaying()) { + state = 0; + } + break; + } + + if (new_jiffies > jiffies) { + jiffies = new_jiffies; + sync1->tick(jiffies); + flashDebug(); } } diff --git a/Synchrotron.cpp b/Synchrotron.cpp index facc0a3..3ed1c32 100644 --- a/Synchrotron.cpp +++ b/Synchrotron.cpp @@ -37,10 +37,9 @@ Synchrotron::discharge() { } Synchrotron::tick(unsigned long jiffies) { - float adj = (float)ticks / (float)tickrate; - byte raa = r * adj; - byte gaa = g * adj; - byte baa = b * adj; + byte raa = r * ticks / tickrate; + byte gaa = g * ticks / tickrate; + byte baa = b * ticks / tickrate; byte ra = r - raa; byte ga = g - gaa; byte ba = b - baa;