I've attached the pieces of my code that matter. Essentially I'm going to have multiple LEDs patterns and multiple wave files to choose from but I am testing the basics with just 2 switches until I get my order in.
Code: Select all
void loop() {
byte led_choice, music_choice, r_index, r_middle, r_ring, r_pinky,
l_index, l_middle, l_ring, l_pinky, r_hand, l_hand;
r_index = digitalRead(right_index);
r_middle = digitalRead(right_middle);
r_ring = digitalRead(right_ring);
r_pinky = digitalRead(right_pinky);
l_index = digitalRead(left_index);
l_middle = digitalRead(left_middle);
l_ring = digitalRead(left_ring);
l_pinky = digitalRead(left_pinky);
r_hand = r_index + 2 * r_middle + 4 * r_ring + 8 * r_pinky;
l_hand = l_index + 2 * l_middle + 4 * l_ring + 8 * l_pinky;
if(r_index)
{
Serial.println("Start playing Mr. Roboto");
playcomplete("mrroboto.wav");
Serial.println("Out of the placomplete function");
}
if(r_middle)
{
Serial.println("Start playing CylonLoop");
CylonLoop(Cylon_Wait);
Serial.println("Done playing CylonLoop");
}
}
void CylonLoop(unsigned int CylonWait)
{
Serial.println("Cylon Loop");
int i, j, temp;
// Start by turning all pixels off:
for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);
for (i=0; i<LedPerStrand; i++)
{
for(j = 0; j < nStrand; j++)
{
temp = i + (j*LedPerStrand);
strip.setPixelColor(temp, strip.Color(127, 0, 0)); // Set new pixel 'on'
if(i-1 >= 0)
{
temp = temp - 1;
strip.setPixelColor(temp, strip.Color(64, 0, 0)); // Set training pixel to 50%
}
if(i-2 >= 0)
{
temp = temp - 1;
strip.setPixelColor(temp, strip.Color(16, 0, 0)); // Dim trailing pixel
}
if(i-3 >= 0)
{
temp = temp - 1;
strip.setPixelColor(temp, strip.Color(0, 0, 0)); // Turn off trailing pixel
}
}
strip.show(); // Refresh LED states
delay(CylonWait);
}
strip.setPixelColor(i-1, strip.Color(0, 0, 0)); // Set last training pixel off
for (i=(LedPerStrand-1); i>=0; i--)
{
for(j = 0; j < nStrand; j++)
{
temp = i + (j*LedPerStrand);
strip.setPixelColor(temp, strip.Color(127, 0, 0)); // Set new pixel 'on'
if(i+1 < LedPerStrand)
{
temp = temp + 1;
strip.setPixelColor(temp, strip.Color(64, 0, 0)); // Set training pixel to 50%
}
if(i+2 < LedPerStrand)
{
temp = temp + 1;
strip.setPixelColor(temp, strip.Color(16, 0, 0)); // Dim trailing pixel
}
if(i+3 < LedPerStrand)
{
temp = temp + 1;
strip.setPixelColor(temp, strip.Color(0, 0, 0)); // Turn off trailing pixel
}
}
strip.show(); // Refresh LED states
delay(CylonWait);
}
}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
// while (wave.isplaying) {
// do nothing while its playing
//}
// now its done playing
}
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
return;
//wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring("Couldn't open file "); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
}
// ok time to play! start playback
wave.play();
}