-
Changes
06/13/2015 at 19:59 • 0 commentsCurrent state:
I've switched out the mic for better gain, and now have a small Neopixel ring for display.
Updated sketch
#include <Adafruit_NeoPixel.h> #include <avr/power.h> #include <Audio.h> #include <Wire.h> #include <SPI.h> #include <SD.h> #define PIN 5 Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800); AudioInputAnalog adc1; AudioAnalyzeFFT1024 myFFT; AudioConnection patchCord1(adc1, 0, myFFT, 0); int dled = 13; void setup() { pinMode(dled, OUTPUT); AudioMemory(12); // Configure the window algorithm to use myFFT.windowFunction(AudioWindowHanning1024); strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { float n; int i; int p; if (myFFT.available()) { // each time new FFT data is available for (i=0; i<strip.numPixels(); i++) { n = myFFT.read(i+5); if (n > 0.05) { p = (n+i)*1000; digitalWrite(dled, HIGH); strip.setPixelColor(i, Wheel(p)); strip.show(); } } digitalWrite(dled, LOW); colorWipe(strip.Color(0, 0, 0), 1); } } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } else { WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } }
-
First Arduino sketch
06/06/2015 at 03:36 • 0 commentsMic is on pin 16 and LEDs are on PWM 23 and 22. The Teensy LED lights up for general frequency detection and the two LEDs light up and fade out at two higher frequencies.
#include <Audio.h> #include <Wire.h> #include <SPI.h> #include <SD.h> AudioInputAnalog adc1; AudioAnalyzeFFT1024 myFFT; AudioConnection patchCord1(adc1, 0, myFFT, 0); int aledg = 23; int aledr = 22; int dled = 13; int brightness1 = 0; int brightness2 = 0; void setup() { pinMode(aledg, OUTPUT); pinMode(aledr, OUTPUT); pinMode(dled, OUTPUT); AudioMemory(12); // Configure the window algorithm to use myFFT.windowFunction(AudioWindowHanning1024); } void loop() { float n; int i; if (myFFT.available()) { // each time new FFT data is available for (i=4; i<175; i++) { n = myFFT.read(i); if (n >= 0.10) { digitalWrite(dled, HIGH); } } if ( myFFT.read(16) >= 0.10 ) { brightness1 = 255; } if ( myFFT.read(13) >= 0.10 ) { brightness2 = 255; } analogWrite(aledg, brightness1); analogWrite(aledr, brightness2); brightness1 = brightness1 -5; brightness2 = brightness2 -5; digitalWrite(dled, LOW); } }