I had this posted under Project Guidance. but i think Programming Questions is the appropriate place for this. sorry for the double post
I want to build an led drum light similar to this one
LED snare drum.AVI - YouTube .
I am new to the arduino.I have a piezo attached to analog pin A0. I tried to combine the array example sketch with the knock sensor sketch. I was eventually able to get the array to work with the piezo but it goes through the whole array when the piezo is greater than the threshold,
How would i increment the array pointer +- 1 one time per event ? Or is there an easier way to do this ?
I'm having trouble keeping it from running through the whole array here's what I have so far, if any one could point me in the right direction I would appreciate it. also I have included a video of how it acts with the current code
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
int timer = 160; // The higher the number, the slower the timing.
int ledPins[] = {
13, 8, 12, 9, 11, 10, }; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length of the array)
int sensorReading = 0; // variable to store the value read from the sensor pin
void setup() {
int thisPin;
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
sensorReading = analogRead(knockSensor);
// loop from the lowest pin to the highest:
if (sensorReading >= threshold) {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}
// loop from the highest pin to the lowest:
if (sensorReading >= threshold) {
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}
}
I would like to build this for my nephew
Here's a link to a video of my nephews band