mirror of https://github.com/nealey/proton
Added all states, all sounds, this is usable
This commit is contained in:
parent
2424f3e672
commit
e58a19a2d1
|
@ -10,7 +10,7 @@ MusicPlayer::MusicPlayer(int8_t cs, int8_t dcs, int8_t dreq, int8_t cardcs)
|
||||||
{
|
{
|
||||||
musicPlayer = new Adafruit_VS1053_FilePlayer(cs, dcs, dreq, cardcs);
|
musicPlayer = new Adafruit_VS1053_FilePlayer(cs, dcs, dreq, cardcs);
|
||||||
musicPlayer->begin();
|
musicPlayer->begin();
|
||||||
musicPlayer->setVolume(20, 20); // lower = louder
|
musicPlayer->setVolume(1, 1); // lower = louder
|
||||||
musicPlayer->sineTest(0x44, 500);
|
musicPlayer->sineTest(0x44, 500);
|
||||||
SD.begin(cardcs);
|
SD.begin(cardcs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,22 +65,29 @@ void loop() {
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 0:
|
case 0:
|
||||||
if (trigger) {
|
if (trigger && music->startPlayingFile("track001.mp3")) {
|
||||||
if (music->startPlayingFile("track001.mp3")) {
|
|
||||||
state = 1;
|
state = 1;
|
||||||
sync1->charge();
|
sync1->charge();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (! music->isPlaying()) {
|
if (! music->isPlaying()) {
|
||||||
if (music->startPlayingFile("track002.mp3")) {
|
state = 3;
|
||||||
state = 4;
|
|
||||||
sync1->standby();
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (trigger && music->startPlayingFile("track003.mp3")) {
|
||||||
|
state = 4;
|
||||||
|
sync1->fire();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
if (! trigger && music->startPlayingFile("track002.mp3")) {
|
||||||
|
state = 5;
|
||||||
|
sync1->discharge();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
if (! music->isPlaying()) {
|
if (! music->isPlaying()) {
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,29 +12,47 @@ Synchrotron::Synchrotron(uint16_t n, uint8_t p, neoPixelType t)
|
||||||
cur = 0;
|
cur = 0;
|
||||||
pxl->begin();
|
pxl->begin();
|
||||||
pxl->show();
|
pxl->show();
|
||||||
|
|
||||||
|
// Inital values of 0 will make it look like it's sort of warming up
|
||||||
|
ticks = 0;
|
||||||
|
tickrate = 200;
|
||||||
|
r = 0;
|
||||||
|
g = 0;
|
||||||
|
b = 0;
|
||||||
|
|
||||||
standby();
|
standby();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Synchrotron::transition(int duration, int final_tickrate, byte final_r, byte final_g, byte final_b)
|
||||||
|
{
|
||||||
|
transition_length = duration;
|
||||||
|
transition_elapsed = 0;
|
||||||
|
|
||||||
|
dtickrate = (final_tickrate - tickrate) / (float)duration;
|
||||||
|
dr = (final_r - r) / (float)duration;
|
||||||
|
dg = (final_g - g) / (float)duration;
|
||||||
|
db = (final_b - b) / (float)duration;
|
||||||
|
|
||||||
|
initial_tickrate = tickrate;
|
||||||
|
initial_r = r;
|
||||||
|
initial_g = g;
|
||||||
|
initial_b = b;
|
||||||
|
}
|
||||||
|
|
||||||
Synchrotron::standby() {
|
Synchrotron::standby() {
|
||||||
tickrate = 12;
|
transition(400, 12, brightness, 0, 0);
|
||||||
ticks = 0;
|
|
||||||
r = brightness;
|
|
||||||
g = 0;
|
|
||||||
b = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Synchrotron::charge() {
|
Synchrotron::charge() {
|
||||||
tickrate = 2;
|
transition(400, 2, brightness, brightness/8, 0);
|
||||||
ticks = 0;
|
|
||||||
r = brightness;
|
|
||||||
g = brightness / 8;
|
|
||||||
b = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Synchrotron::fire() {
|
Synchrotron::fire() {
|
||||||
|
transition(40, 1, brightness/8, brightness/4, brightness/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Synchrotron::discharge() {
|
Synchrotron::discharge() {
|
||||||
|
standby();
|
||||||
}
|
}
|
||||||
|
|
||||||
Synchrotron::tick(unsigned long jiffies) {
|
Synchrotron::tick(unsigned long jiffies) {
|
||||||
|
@ -51,8 +69,16 @@ Synchrotron::tick(unsigned long jiffies) {
|
||||||
pxl->show();
|
pxl->show();
|
||||||
|
|
||||||
ticks += 1;
|
ticks += 1;
|
||||||
if (ticks == tickrate) {
|
if (ticks >= tickrate) {
|
||||||
ticks = 0;
|
|
||||||
cur = (cur + 1) % npixels;
|
cur = (cur + 1) % npixels;
|
||||||
|
ticks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transition_length > transition_elapsed) {
|
||||||
|
tickrate = initial_tickrate + (dtickrate * transition_elapsed);
|
||||||
|
r = initial_r + (dr * transition_elapsed);
|
||||||
|
g = initial_g + (dg * transition_elapsed);
|
||||||
|
b = initial_b + (db * transition_elapsed);
|
||||||
|
transition_elapsed += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,13 @@ class Synchrotron {
|
||||||
int tickrate; // How many millis between pixel position changes
|
int tickrate; // How many millis between pixel position changes
|
||||||
int ticks; // How many ticks have elapsed since last position change
|
int ticks; // How many ticks have elapsed since last position change
|
||||||
byte r, g, b; // Current color
|
byte r, g, b; // Current color
|
||||||
|
|
||||||
|
int transition_length, transition_elapsed;
|
||||||
|
int initial_tickrate, initial_r, initial_g, initial_b;
|
||||||
|
float dtickrate, dr, dg, db;
|
||||||
public:
|
public:
|
||||||
Synchrotron(uint16_t n, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800);
|
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);
|
||||||
standby();
|
standby();
|
||||||
charge();
|
charge();
|
||||||
fire();
|
fire();
|
||||||
|
|
Loading…
Reference in New Issue