Guest User

Untitled

a guest
Jan 6th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #define N_PIXELS  22  // Number of pixels you are using
  4. #define MIC_PIN    1  // Microphone is attached to Trinket GPIO #2/Gemma D2 (A1)
  5. #define LED_PIN    6  // NeoPixel LED strand is connected to GPIO #0 / D0
  6. #define DC_OFFSET  0  // DC offset in mic signal - if unusure, leave 0
  7. #define NOISE     80  // Noise/hum/interference in mic signal
  8. #define SAMPLES   60  // Length of buffer for dynamic level adjustment
  9. #define TOP       (N_PIXELS +1) // Allow dot to go slightly off scale
  10. // Comment out the next line if you do not want brightness control or have a Gemma
  11. #define POT_PIN    1  // if defined, a potentiometer is on GPIO #3 (A3, Trinket only)
  12.  
  13. byte
  14.   peak      = 0,      // Used for falling dot
  15.   dotCount  = 0,      // Frame counter for delaying dot-falling speed
  16.   volCount  = 0;      // Frame counter for storing past volume data
  17.  
  18. int
  19.   vol[SAMPLES],       // Collection of prior volume samples
  20.   lvl       = 10,     // Current "dampened" audio level
  21.   minLvlAvg = 0,      // For dynamic adjustment of graph low & high
  22.   maxLvlAvg = 512;
  23.  
  24. long previousMillis = 0;        // will store last time LED was updated
  25.  
  26. long interval = 3;           // interval at which to blink in minutes
  27.  
  28. Adafruit_NeoPixel  strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
  29.  
  30. void setup() {
  31.   memset(vol, 0, sizeof(vol));
  32.  
  33.   strip.setBrightness(10);
  34.   strip.begin();
  35.   strip.show();
  36.  
  37. }
  38.  
  39. void loop()
  40. {
  41.           dropdown(10);
  42. }
  43.  
  44. void dropdown(uint8_t wait)
  45. {
  46.   long ledcolor=255/(strip.numPixels());
  47.  
  48.   for (int cnt = 0; cnt<strip.numPixels(); cnt++)
  49.   {
  50.    for (int i=strip.numPixels(); i>=cnt;i--)
  51.       {
  52.        strip.setPixelColor(i, Wheel(((ledcolor)*(cnt)) & 255));
  53.        strip.setPixelColor(i+1, 0);
  54.        strip.show();
  55.        delay(wait);
  56.        
  57.       }
  58. }
  59. }
  60.  
  61. // Input a value 0 to 255 to get a color value.
  62. // The colors are a transition r - g - b - back to r.
  63. uint32_t Wheel(byte WheelPos) {
  64.   if(WheelPos < 85) {
  65.    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  66.   } else if(WheelPos < 170) {
  67.    WheelPos -= 85;
  68.    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  69.   } else {
  70.    WheelPos -= 170;
  71.    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment