Adafruits NeoPixels are awesome, the Arduino of LEDs. There are a couple tutorials on sound reactive LEDs with the NeoPixels, including one on Adafruit about making a drum set light up when you hit it. The video makes it look like it works, but look carefully and you’ll see other drums lighting up when a different drum is being played. That’s because they’re using microphones which are way too sensitive for a intra-drum set environment. To eliminate the cross talk, replace the mic with a piezo element and read the voltage spikes generated by force of the drum hits.
See it real life!
See it in schematic!
(coming soon)
See it in code!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
/* Adaptation of Knock sensor and sound-reactive drums by Michael Sizemore 8/27/14 Take input from a Piezo to detect drum hit. Once hit, flash LEDs white and fade down to a single color before fading out. Expect the refresh rate of the neopixels to be ~100-200Hz */ #include <Adafruit_NeoPixel.h> //Variables defining envionrment & hardware setup #define N_PIXELS 60 // Number of pixels you are using #define THRESHOLD 100 // threshold value to determine is signal is noise #define INTERVAL 4 // cycle time in milliseconds - fade out every x ms #define RED_STEP 15 // decrease red by x each interval #define GREEN_STEP 30 // decrease green by x each interval #define BLUE_STEP 15 // decrease blue by x each interval const int neopixelPin = 0; // Neopixel data pin const int ledPin = 1; // led connected to digital pin 1 - delete this if you don't want the LED on the Gemma board to light up const int knockSensor = 1; // the piezo is connected to analog pin 1 int sensorReading = 0; // variable to store the value read from the sensor pin int ledState = LOW; // variable used to store the last LED status, to toggle the light int red = 0; int blue = 0; int green = 0; unsigned long last_time = 0; Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, neopixelPin, NEO_GRB + NEO_KHZ800); void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT strip.begin(); strip.setBrightness(255); } void loop() { uint8_t i; unsigned long current_time; // read the piezo sensor sensorReading = analogRead(knockSensor); // if the sensor reading is greater than the threshold: if (sensorReading >= THRESHOLD) { //Turn the NeoPixels to bright white red = 255; blue = 255; green = 255; for(i=0; i<N_PIXELS; i++) { strip.setPixelColor(i, red, green, blue); } digitalWrite(ledPin, HIGH); last_time = millis(); } else { // Sensor reading is too low, fade the LEDs off digitalWrite(ledPin, LOW); current_time = millis(); if (current_time - last_time > INTERVAL){ last_time = current_time; // reset the timer if (red>RED_STEP) red = red - RED_STEP; else red = 0; if (blue>BLUE_STEP) blue = blue - BLUE_STEP; else blue = 0; if (green>GREEN_STEP) green = green - GREEN_STEP; else green = 0; // update the pixels for(i=0; i<N_PIXELS; i++) { strip.setPixelColor(i, red, green, blue); } } } //Send out the udpates strip.show(); // Update strip } |