Created
April 26, 2015 17:16
-
-
Save sulram/9eb58b62f701db079e05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include <NanoSoftSensor.h> | |
#define LED_1 2 | |
#define LED_2 3 | |
#define LED_F 8 | |
NanoSoftSensor soft_audio = NanoSoftSensor(3); | |
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(100, LED_1, NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(100, LED_2, NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoPixel feedback = Adafruit_NeoPixel(2, LED_F, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
strip1.begin(); | |
strip1.show(); | |
strip2.begin(); | |
strip2.show(); | |
feedback.begin(); | |
feedback.show(); | |
} | |
void loop() { | |
// read RGBI A4-A7 | |
int R = pot_map(analogRead(A4)); | |
int G = pot_map(analogRead(A5)); | |
int B = pot_map(analogRead(A6)); | |
int I = pot_map(analogRead(A7)); | |
// read audio pin A0 | |
int audio = analogRead(A0) - 512; | |
// VU calculation | |
if (audio < 0) { | |
audio = abs(audio); | |
} | |
// map audio to leds | |
audio = map(audio, 0, 256, 0, 100); | |
// soft audio | |
soft_audio.update(audio); | |
// turn off leds | |
for (uint16_t i = 0; i < strip1.numPixels(); i++) { | |
strip1.setPixelColor(i, 0, 0, 0); | |
strip2.setPixelColor(i, 0, 0, 0); | |
} | |
// turn leds | |
for (uint16_t i = 0; i < audio; i++) { | |
//for (uint16_t i = 0; i < soft_audio.value; i++) { | |
strip1.setPixelColor(i, R, G, B); | |
strip2.setPixelColor(i, R, B, G); | |
} | |
strip1.setBrightness(I); | |
strip2.setBrightness(I); | |
strip1.show(); | |
strip2.show(); | |
feedback.setPixelColor(0, G, R, B); | |
feedback.setPixelColor(1, G, R, B); | |
feedback.show(); | |
delay(10); | |
} | |
int pot_map(int val){ | |
return map(val,0,1023,0,255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment