Advertisement
Guest User

Bass-meter

a guest
Oct 11th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include                                            <FastLED.h>
  2.  
  3.  
  4.  
  5. #define LED_PIN                                     5
  6. #define PIEZZO_PIN                                  A5
  7.  
  8. #define NUM_LEDS                                    8
  9. #define BRIGHTNESS                                  255
  10.  
  11. #define LED_TYPE                                    WS2812B
  12. #define COLOR_ORDER                                 GRB
  13.  
  14.  
  15. CRGB leds[NUM_LEDS];
  16. uint16_t piezzoValue                =               0;
  17. uint32_t lastUpdate                 =               0;
  18. uint8_t r, g, b                     =               0;
  19.  
  20.  
  21. void fillLED();
  22.  
  23.  
  24. void setup(void)
  25. {
  26.     delay(3000);
  27.  
  28.     FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  29.     FastLED.setBrightness(BRIGHTNESS);
  30. }
  31.  
  32. void loop(void)
  33. {
  34.     piezzoValue = analogRead(PIEZZO_PIN);
  35.  
  36.     if (piezzoValue > 10)
  37.     {
  38.         if (millis() - lastUpdate > 1000)
  39.         {
  40.             r = random(255);
  41.             g = random(255);
  42.             b = random(255);
  43.  
  44.             lastUpdate = millis();
  45.         }
  46.  
  47.         piezzoValue = map(piezzoValue, 64, 512, 16, 225);
  48.         FastLED.setBrightness(piezzoValue);
  49.     }
  50.     else
  51.     {
  52.         r = g = b = 0;
  53.         FastLED.setBrightness(0);      
  54.     }
  55.  
  56.     fillLED();
  57.     delay(50);
  58. }
  59.  
  60.  
  61. void fillLED()
  62. {
  63.     for (uint8_t i = 0; i < NUM_LEDS; i++)
  64.     {
  65.         leds[i].r = r;
  66.         leds[i].g = g;
  67.         leds[i].b = b;
  68.     }
  69.  
  70.     FastLED.show();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement