Added wand and 7seg displays

This commit is contained in:
Neale Pickett 2016-10-02 11:59:11 -06:00
parent e58a19a2d1
commit 4068174d1a
5 changed files with 201 additions and 29 deletions

View File

@ -10,26 +10,44 @@
#include "Synchrotron.h"
// Music Player
#define MUSIC_CS 7
#define MUSIC_DATA 6
#define MUSIC_CARDCS 4
#define MUSIC_REQ 3
#define MUSIC_MCS 7
#define MUSIC_DCS 6
#define MUSIC_CCS 4
#define MUSIC_DRQ 0 // Cut trace on board and wire to 0, so you can use 3 for SPI
MusicPlayer *music;
// LED output scaling
#define brightness 255
// Synchrotron
#define SYNC1_NPIXELS 24
#define SYNC1_DATA 5
Synchrotron *sync1;
// Neutrona Wand
#define WAND1_NPIXELS 14
#define WAND1_DATA 9
Synchrotron *wand1;
// Displays
Adafruit_7segment disp1;
Adafruit_7segment disp2;
// Debug LED
#define DEBUG 13
// Inputs
#define TRIGGER 8
#define POT1 A0
// global time counter
unsigned long jiffies = 0;
// 6 seems to be about what my overly-critical brain needs to buffer out
// any delays caused by NMI sections of music player code so that they're unnoticeable
#define MILLIS_PER_JIFFY 6
void setup() {
randomSeed(analogRead(12));
@ -40,10 +58,20 @@ void setup() {
pinMode(DEBUG, OUTPUT);
// music player, this sets up SPI for us
music = new MusicPlayer(MUSIC_CS, MUSIC_DATA, MUSIC_REQ, MUSIC_CARDCS);
music = new MusicPlayer(MUSIC_MCS, MUSIC_DCS, MUSIC_DRQ, MUSIC_CCS);
// synchrotron
sync1 = new Synchrotron(SYNC1_NPIXELS, SYNC1_DATA);
// nuetrona wand
wand1 = new Synchrotron(WAND1_NPIXELS, WAND1_DATA);
// 7segment displays
disp1 = Adafruit_7segment();
disp1.begin(0x70);
disp2 = Adafruit_7segment();
disp2.begin(0x71);
}
@ -56,39 +84,39 @@ void flashDebug() {
void loop() {
static int state = 0;
// 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;
static float disp2val = 40.83;
unsigned long new_jiffies = millis() / MILLIS_PER_JIFFY;
boolean trigger = ! digitalRead(TRIGGER);
music->poll(jiffies);
switch (state) {
case 0:
if (trigger && music->startPlayingFile("track001.mp3")) {
state = 1;
sync1->charge();
case 0: // move to steady state
sync1->transition(400, 12, brightness, 0, 0);
wand1->transition(400, 24, brightness, 0, 0);
state = 10;
break;
case 10: // waiting for charge button
if (trigger && sync1->transitioned() && music->startPlayingFile("track001.mp3")) {
state = 20;
sync1->transition(700, 2, brightness, brightness/8, 0);
wand1->transition(700, 10, brightness, brightness/8, 0);
}
break;
case 1:
if (! music->isPlaying()) {
state = 3;
case 20: // charge button pressed
if (sync1->transitioned()) {
state = 30;
}
break;
case 3:
if (trigger && music->startPlayingFile("track003.mp3")) {
state = 4;
sync1->fire();
case 30: // waiting for fire button
if (trigger && music->startPlayingFile("nutrona.mp3")) {
state = 40;
sync1->transition(40, 1, brightness/8, brightness/4, brightness/2);
wand1->transition(40, 5, brightness/6, brightness/2, brightness/6);
}
break;
case 4:
case 40: // fire button pressed
if (! trigger && music->startPlayingFile("track002.mp3")) {
state = 5;
sync1->discharge();
}
break;
case 5:
if (! music->isPlaying()) {
state = 0;
}
break;
@ -97,6 +125,17 @@ void loop() {
if (new_jiffies > jiffies) {
jiffies = new_jiffies;
sync1->tick(jiffies);
wand1->tick(jiffies);
if (jiffies % 10 == 0) {
// This is expensive
disp1.printFloat(5198 * sync1->speed());
disp1.writeDisplay();
disp2val = analogRead(POT1) / 10.0;
disp2.printFloat(disp2val, 1);
disp2.writeDisplay();
}
flashDebug();
}
}

View File

@ -39,12 +39,22 @@ Synchrotron::transition(int duration, int final_tickrate, byte final_r, byte fin
initial_b = b;
}
bool
Synchrotron::transitioned() {
return (transition_elapsed >= transition_length);
}
float
Synchrotron::speed() {
return 1 / ftickrate;
}
Synchrotron::standby() {
transition(400, 12, brightness, 0, 0);
}
Synchrotron::charge() {
transition(400, 2, brightness, brightness/8, 0);
transition(700, 2, brightness, brightness/8, 0);
}
Synchrotron::fire() {
@ -75,10 +85,11 @@ Synchrotron::tick(unsigned long jiffies) {
}
if (transition_length > transition_elapsed) {
tickrate = initial_tickrate + (dtickrate * transition_elapsed);
transition_elapsed += 1;
ftickrate = initial_tickrate + (dtickrate * transition_elapsed);
tickrate = ftickrate;
r = initial_r + (dr * transition_elapsed);
g = initial_g + (dg * transition_elapsed);
b = initial_b + (db * transition_elapsed);
transition_elapsed += 1;
}
}

View File

@ -14,9 +14,12 @@ class Synchrotron {
int transition_length, transition_elapsed;
int initial_tickrate, initial_r, initial_g, initial_b;
float dtickrate, dr, dg, db;
float ftickrate;
public:
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);
bool transitioned();
float speed();
standby();
charge();
fire();

BIN
nutrona.mp3 Normal file

Binary file not shown.

119
radlove.svg Normal file
View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="141.89731mm"
height="141.89731mm"
viewBox="0 0 502.78573 502.78572"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="radlove.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="240.22136"
inkscape:cy="248.73745"
inkscape:document-units="px"
inkscape:current-layer="g4238"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1920"
inkscape:window-height="1016"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-120.0357,-286.68361)">
<g
id="g4238">
<circle
r="242.39842"
cy="538.07648"
cx="371.42856"
id="path4136"
style="opacity:1;fill:#ffff00;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:17.98888016;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
d="m 479.19755,351.41513 a 215.53796,215.53796 0 0 1 107.76897,186.66135 l -215.53796,0 z"
sodipodi:end="0"
sodipodi:start="5.2359878"
sodipodi:ry="215.53796"
sodipodi:rx="215.53796"
sodipodi:cy="538.07648"
sodipodi:cx="371.42856"
sodipodi:type="arc"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:15.9955101;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
id="circle4161" />
<path
d="M 155.89059,538.07647 A 215.53796,215.53796 0 0 1 263.65958,351.41513 l 107.76898,186.66135 z"
sodipodi:end="4.1887902"
sodipodi:start="3.1415927"
sodipodi:ry="215.53796"
sodipodi:rx="215.53796"
sodipodi:cy="538.07648"
sodipodi:cx="371.42856"
sodipodi:type="arc"
id="path4163"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:15.9955101;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:15.9955101;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
id="path4165"
sodipodi:type="arc"
sodipodi:cx="371.42856"
sodipodi:cy="538.07648"
sodipodi:rx="215.53796"
sodipodi:ry="215.53796"
sodipodi:start="1.0471976"
sodipodi:end="2.0943951"
d="m 479.19753,724.73783 a 215.53796,215.53796 0 0 1 -215.53795,0 L 371.42856,538.07648 Z" />
</g>
<g
transform="matrix(0.79020839,0,0,0.79020839,-76.502899,240.96985)"
inkscape:label="Layer 1"
id="layer1-7">
<g
transform="matrix(0.97556,0,0,0.97556,-18.264,24.845)"
style="stroke:#af024c;stroke-width:2.87529993"
id="g17152">
<path
d="m 540.37525,265.35878 c -29.691,0.61893 -55.518,19.25 -64.878,50.794 -15.808,81.974 75.349,116.47 125.55,165.46 43.586,-56.698 128.92,-71.353 124.66,-155.21 -3.7056,-18.7 -14.155,-33.925 -28.166,-44.632 -18.775,-14.365 -44.927,-19.303 -67.275,-10.718 -11.956,4.22 -22.844,11.552 -30.981,21.271 -14.141,-17.43 -36.494,-27.452 -58.909,-26.962 z"
style="fill:#d40055;stroke:#000000;stroke-width:15.06948352;stroke-miterlimit:4;stroke-dasharray:none"
sodipodi:nodetypes="cccccccc"
id="path8148"
inkscape:connector-curvature="0" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB