Button more responsive, sorta

This commit is contained in:
Neale Pickett 2016-09-25 22:43:31 -06:00
parent c3f635e1f9
commit 059eda4c8d
4 changed files with 35 additions and 13 deletions

View File

@ -28,6 +28,12 @@ MusicPlayer::startPlayingFile(const char *trackname)
return musicPlayer->startPlayingFile(trackname); return musicPlayer->startPlayingFile(trackname);
} }
boolean
MusicPlayer::isPlaying()
{
return musicPlayer->playingMusic;
}
void void
MusicPlayer::stopPlaying() MusicPlayer::stopPlaying()
{ {

View File

@ -9,6 +9,7 @@ public:
MusicPlayer(int8_t cs, int8_t dcs, int8_t dreq, int8_t cardcs); MusicPlayer(int8_t cs, int8_t dcs, int8_t dreq, int8_t cardcs);
boolean startPlayingFile(const char *trackname); boolean startPlayingFile(const char *trackname);
void setVolume(uint8_t left, uint8_t right); void setVolume(uint8_t left, uint8_t right);
boolean isPlaying();
void stopPlaying(); void stopPlaying();
void poll(unsigned long jiffies); // Call this once per loop() void poll(unsigned long jiffies); // Call this once per loop()
}; };

View File

@ -25,7 +25,7 @@ Synchrotron *sync1;
#define DEBUG 13 #define DEBUG 13
// Inputs // Inputs
#define TRIGGER 9 #define TRIGGER 8
// global time counter // global time counter
unsigned long jiffies = 0; unsigned long jiffies = 0;
@ -63,18 +63,34 @@ void loop() {
music->poll(jiffies); music->poll(jiffies);
if (state == 0) { switch (state) {
if (new_jiffies > jiffies) { case 0:
if (trigger) { if (trigger) {
if (music->startPlayingFile("track001.mp3")) {
state = 1; state = 1;
music->startPlayingFile("track001.mp3");
sync1->charge(); sync1->charge();
} }
}
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; jiffies = new_jiffies;
sync1->tick(jiffies); sync1->tick(jiffies);
flashDebug(); flashDebug();
} }
}
} }

View File

@ -37,10 +37,9 @@ Synchrotron::discharge() {
} }
Synchrotron::tick(unsigned long jiffies) { Synchrotron::tick(unsigned long jiffies) {
float adj = (float)ticks / (float)tickrate; byte raa = r * ticks / tickrate;
byte raa = r * adj; byte gaa = g * ticks / tickrate;
byte gaa = g * adj; byte baa = b * ticks / tickrate;
byte baa = b * adj;
byte ra = r - raa; byte ra = r - raa;
byte ga = g - gaa; byte ga = g - gaa;
byte ba = b - baa; byte ba = b - baa;