2016-09-25 16:57:35 -06:00
|
|
|
// Proton Pack with NeoPixels
|
|
|
|
// Boy howdy do these make everything easy
|
|
|
|
|
2016-09-25 16:57:13 -06:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <Wire.h>
|
2016-09-25 16:57:35 -06:00
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#include <Adafruit_LEDBackpack.h>
|
|
|
|
#include <Adafruit_GFX.h>
|
2016-09-25 21:51:15 -06:00
|
|
|
#include "MusicPlayer.h"
|
|
|
|
#include "Synchrotron.h"
|
2016-09-25 16:57:35 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// Music Player
|
|
|
|
#define MUSIC_CS 7
|
|
|
|
#define MUSIC_DATA 6
|
|
|
|
#define MUSIC_CARDCS 4
|
|
|
|
#define MUSIC_REQ 3
|
|
|
|
MusicPlayer *music;
|
2016-09-25 16:57:35 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// Synchrotron
|
|
|
|
#define SYNC1_NPIXELS 24
|
|
|
|
#define SYNC1_DATA 5
|
|
|
|
Synchrotron *sync1;
|
2016-09-25 16:57:35 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// Debug LED
|
|
|
|
#define DEBUG 13
|
2016-09-25 16:57:35 -06:00
|
|
|
|
|
|
|
// Inputs
|
2016-09-25 21:51:15 -06:00
|
|
|
#define TRIGGER 9
|
2016-09-25 16:57:13 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// global time counter
|
2016-09-25 16:57:13 -06:00
|
|
|
unsigned long jiffies = 0;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
randomSeed(analogRead(12));
|
|
|
|
|
2016-09-25 16:57:35 -06:00
|
|
|
// inputs
|
2016-09-25 16:57:13 -06:00
|
|
|
pinMode(TRIGGER, INPUT_PULLUP);
|
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// outputs
|
|
|
|
pinMode(DEBUG, OUTPUT);
|
2016-09-25 16:57:35 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// music player, this sets up SPI for us
|
|
|
|
music = new MusicPlayer(MUSIC_CS, MUSIC_DATA, MUSIC_REQ, MUSIC_CARDCS);
|
2016-09-25 16:57:13 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
// synchrotron
|
|
|
|
sync1 = new Synchrotron(SYNC1_NPIXELS, SYNC1_DATA);
|
2016-09-25 16:57:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-25 16:57:35 -06:00
|
|
|
void flashDebug() {
|
2016-09-25 21:51:15 -06:00
|
|
|
uint8_t val;
|
2016-09-25 16:57:35 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
val = (jiffies % 100) < 50;
|
|
|
|
digitalWrite(DEBUG, val);
|
2016-09-25 16:57:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-09-25 21:51:15 -06:00
|
|
|
static int state = 0;
|
2016-09-25 16:57:35 -06:00
|
|
|
// 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;
|
2016-09-25 21:51:15 -06:00
|
|
|
boolean trigger = ! digitalRead(TRIGGER);
|
2016-09-25 16:57:13 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
music->poll(jiffies);
|
|
|
|
|
|
|
|
if (state == 0) {
|
|
|
|
if (new_jiffies > jiffies) {
|
|
|
|
if (trigger) {
|
|
|
|
state = 1;
|
|
|
|
music->startPlayingFile("track001.mp3");
|
|
|
|
sync1->charge();
|
|
|
|
}
|
2016-09-25 16:57:13 -06:00
|
|
|
|
2016-09-25 21:51:15 -06:00
|
|
|
jiffies = new_jiffies;
|
|
|
|
sync1->tick(jiffies);
|
|
|
|
flashDebug();
|
2016-09-25 16:57:35 -06:00
|
|
|
}
|
|
|
|
}
|
2016-09-25 16:57:13 -06:00
|
|
|
}
|
|
|
|
|