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);
}
boolean
MusicPlayer::isPlaying()
{
return musicPlayer->playingMusic;
}
void
MusicPlayer::stopPlaying()
{

View File

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

View File

@ -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) {
switch (state) {
case 0:
if (trigger) {
if (music->startPlayingFile("track001.mp3")) {
state = 1;
music->startPlayingFile("track001.mp3");
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;
sync1->tick(jiffies);
flashDebug();
}
}
}

View File

@ -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;