Here's the code. Read the switches, read the piezo elements, fill the red/green/blue arrays based on switch settings, write strip. repeat.
Couple of comments about the video, during the finale when the strip goes white, you can see the right side is brighter. Voltage drop. Need to drive the strip from both sides or middle as well. version 2.
As for calibration, I didn't. Since the Arduino A/D returns a value up to 1023, I never saw higher than 500 or so based on my circuit. What I did was map the value from 0-600 to 0-127 for the relative value:
outputValue1 = map(sensorValue1, 0, 600, 0, 127);
My calibration will be from a pot for each drum to modify the 600 value to make it more sensitive or not. version 2. electronic sensitivity.
I'll draw up a schematic for the piezo elements, but they were just Radio Shack piezo elements that I attached to the buckets about 4 inches from the bottom of the bucket. The drummers flipped them over to play them and the wires just came back to the switch box. I originally was playing with momentary contact buttons, hence the "button" in the code, but I moved to switches for more functionality. The piezo elements were connected to some diodes (rectify step), a zener (5.1 v to protect the arduino), and an RC circuit for a decent decay value. had to play with that since my math didn't work right with the sampling frequency of the loop.
Even though my code is horribly inefficient, because it does the same things over and over, the timing is very stable per loop. Very evident on the chase sequences where there are no hiccups. I'd love to get some pointers on arrays and optimizations since version 2 will include both strips and a few more outputs.
And because the code is modular, adding another strip and another drum or two wouldn't be hard.
The sparkle effect was my favorite so I'll let the interested folks peruse the finale code for that. involved random values larger than the decreasing loop variable and pushing that out to the various LEDs.
Thanks for the comments and looking forward to suggestions for improvements. Code in two parts:
#include "LPD8806.h"
#include "SPI.h"
#define button1 22
#define button2 23
#define button3 24
#define button4 25
#define button5 26
#define button6 27
#define button7 28
#define button8 29
#define button9 30
#define button10 31
#define stripSize 160
const int analogInPin1 = A0; // Analog input pin for Drum1
const int analogInPin2 = A1; // Analog input pin for Drum2
const int analogInPin3 = A2; // Analog input pin for Drum3
int sensorValue1 = 0; // value read from the Drum1
int sensorValue2 = 0; // value read from the Drum2
int sensorValue3 = 0; // value read from the Drum3
int outputValue1 = 0; // mapped value for the strip
int outputValue2 = 0; // mapped value for the strip
int outputValue3 = 0; // mapped value for the strip
int redPulseWidthDecay = 4; // Decay value for pulse widths. higher for shorter pulses
int greenPulseWidthDecay = 4; // Decay value for pulse widths. higher for shorter pulses
int bluePulseWidthDecay = 4; // Decay value for pulse widths. higher for shorter pulses
int redGreen = 53; //edge between red and green segments
int greenBlue = 106; //edge between green and blue segments
int redLeft = 0; // Set up edges for loops
int redRight = 53;
int greenLeft= 54;
int greenRight = 106;
int blueLeft = 107;
int blueRight = 160;
int drum1[stripSize]; // set up array for red drum hits
int drum2[stripSize]; // set up array for green drum hits
int drum3[stripSize]; // set up array for blue drum hits
int drum1position=26; // drum location on strip. Centered at 26 for red
int drum2position=80; // 80 for green
int drum3position=134; // 134 for Blue
int redPulseButton=0; // set up button states for six buttons
int greenPulseButton=0;
int bluePulseButton=0;
int redChaseButton=0;
int greenChaseButton=0;
int blueChaseButton=0;
int finaleButton = 0;
int redFullButton = 0;
int greenFullButton = 0;
int blueFullButton = 0;
// use the 51/52 default for hardware SPI on the Mega
LPD8806 strip = LPD8806(stripSize);
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(button3,INPUT);
pinMode(button4,INPUT);
pinMode(button5,INPUT);
pinMode(button6,INPUT);
pinMode(button7,INPUT);
pinMode(button8,INPUT);
pinMode(button9,INPUT);
pinMode(button10,INPUT);
}
void loop() {
//read digital pins and map to variables
redPulseButton = digitalRead(button1);
redChaseButton = digitalRead(button2);
redFullButton = digitalRead(button8);
greenPulseButton = digitalRead(button3);
greenChaseButton = digitalRead(button4);
greenFullButton = digitalRead(button9);
bluePulseButton = digitalRead(button5);
blueChaseButton = digitalRead(button6);
blueFullButton = digitalRead(button10);
finaleButton = digitalRead(button7);
// read the drum values:
sensorValue1 = analogRead(analogInPin1);
sensorValue2 = analogRead(analogInPin2);
sensorValue3 = analogRead(analogInPin3);
// map it to the range of the analog out:
outputValue1 = map(sensorValue1, 0, 600, 0, 127);
outputValue2 = map(sensorValue2, 0, 600, 0, 127);
outputValue3 = map(sensorValue3, 0, 600, 0, 127);
//Finale button hit? Big Red Button
if (finaleButton==1) {
int finaleDecay=1;
/// white for a flash, then decay to red/green/blue
for (int i=0; i<stripSize; i++) {
drum1[i]=127;
drum2[i]=127;
drum3[i]=127;
}
for (int i=0; i<stripSize; i++) {
strip.setPixelColor(i,drum1[i],drum2[i],drum3[i]);
}
strip.show();
delay(1000);
for (int i=0; i<stripSize; i++) {
strip.setPixelColor(i,0,0,0);
}
strip.show();
delay(1500);
// red green blue full for 3 seconds
for (int i=0; i<54; i++) {
drum1[i]=50;
drum2[i]=0;
drum3[i]=0;
}
for (int i=54; i<107; i++) {
drum2[i]=50;
drum1[i]=0;
drum3[i]=0;
}
for (int i=107; i<160; i++) {
drum3[i]=50;
drum1[i]=0;
drum2[i]=0;
}
//slow down the last bit for effect
for (int dimmerLoop=55; dimmerLoop>0;dimmerLoop--) {
for (int i=0; i<54; i++) {
drum1[i]=dimmerLoop-random(0,127);
if (drum1[i]<0) drum1[i]=0;
// drum1[i]=dimmerLoop;
}
for (int i=54; i<107; i++) {
drum2[i]=dimmerLoop-random(0,127);
if (drum2[i]<0) drum2[i]=0;
//drum2[i]=dimmerLoop;
}
for (int i=107; i<160; i++) {
drum3[i]=dimmerLoop-random(0,127);
if (drum3[i]<0) drum3[i]=0;
// drum3[i]=dimmerLoop;
}
for (int i=0; i<stripSize; i++) {
strip.setPixelColor(i,drum1[i],drum2[i],drum3[i]);
}
strip.show();
delay(60);
}
//turn off all LEDs and wait for 20 seconds for someone to turn off power
for (int i=0; i<stripSize; i++) {
strip.setPixelColor(i,0,0,0);
}
strip.show();
delay(20000);
}