Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define N_PIXELS 22 // Number of pixels you are using
- #define MIC_PIN 1 // Microphone is attached to Trinket GPIO #2/Gemma D2 (A1)
- #define LED_PIN 6 // NeoPixel LED strand is connected to GPIO #0 / D0
- #define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
- #define NOISE 80 // Noise/hum/interference in mic signal
- #define SAMPLES 60 // Length of buffer for dynamic level adjustment
- #define TOP (N_PIXELS +1) // Allow dot to go slightly off scale
- // Comment out the next line if you do not want brightness control or have a Gemma
- #define POT_PIN 1 // if defined, a potentiometer is on GPIO #3 (A3, Trinket only)
- byte
- peak = 0, // Used for falling dot
- dotCount = 0, // Frame counter for delaying dot-falling speed
- volCount = 0; // Frame counter for storing past volume data
- int
- vol[SAMPLES], // Collection of prior volume samples
- lvl = 10, // Current "dampened" audio level
- minLvlAvg = 0, // For dynamic adjustment of graph low & high
- maxLvlAvg = 512;
- long previousMillis = 0; // will store last time LED was updated
- long interval = 3; // interval at which to blink in minutes
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- memset(vol, 0, sizeof(vol));
- strip.setBrightness(10);
- strip.begin();
- strip.show();
- }
- void loop()
- {
- dropdown(10);
- }
- void dropdown(uint8_t wait)
- {
- long ledcolor=255/(strip.numPixels());
- for (int cnt = 0; cnt<strip.numPixels(); cnt++)
- {
- for (int i=strip.numPixels(); i>=cnt;i--)
- {
- strip.setPixelColor(i, Wheel(((ledcolor)*(cnt)) & 255));
- strip.setPixelColor(i+1, 0);
- strip.show();
- delay(wait);
- }
- }
- }
- // Input a value 0 to 255 to get a color value.
- // The colors are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- if(WheelPos < 85) {
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- } else if(WheelPos < 170) {
- WheelPos -= 85;
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- } else {
- WheelPos -= 170;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment