Pages: [1]   Go Down
Author Topic: led drum lights  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to build an led drum light similar to this one . 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 ?

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50366
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How would i increment the array pointer +\- 1 one time per event ?
What array pointer?

How do you define an event?
Logged

Offline Offline
Edison Member
*
Karma: 36
Posts: 1340
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm going to guess you need a delay (maybe 100ms ?), assuming your code is otherwise OK.   Of course, the drum-hit doesn't make a nice single digital pulse, and you are going to get multiple triggers if you don't stop and wait while the drum-sound fades-down.

 - Wait for hit (looping)
 - Trigger & read array
 - Incriment to next array element
 - Delay
 - Loop back and wait for another hit...

Or, you might have to make a variable threshold...  So, after a hit/trigger it gets less-sensitive for a few milliseconds.   Then as the milliseconds pass, it gets more sensitive waiting for the next hit. 

I've actually built something like that with an analog circuit - It would automatically set the trigger threshold...   I had a peak-detector charging a capacitor, and that set my threshold-reference.  So a beat comes-in, triggers the lights, and the threshold is automatically set.  (The threshold and signal are run-into a comparator that triggers the lights whenever the signal is greater than the threshold.)   The capacitor would discharge through a resistor, so the threshold would drop and and the thing would get more sensitive the longer it waited for another beat.      (There may have been a bit more to the circuit, but that's the basic idea and the same thing can be done in software.)  The timing was "tuned" so that it "likes" to trigger 3 or 4 times per second to match the beat of a typical song.   
« Last Edit: December 21, 2011, 03:37:27 pm by DVDdoug » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks DVDdoug

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
http://youtu.be/rrxGafQDhAY

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
http://youtu.be/flebuiKXPm0
Logged

Pages: [1]   Go Up
Jump to: