Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 5
- #define PIEZZO_PIN A5
- #define NUM_LEDS 8
- #define BRIGHTNESS 255
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- CRGB leds[NUM_LEDS];
- uint16_t piezzoValue = 0;
- uint32_t lastUpdate = 0;
- uint8_t r, g, b = 0;
- void fillLED();
- void setup(void)
- {
- delay(3000);
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop(void)
- {
- piezzoValue = analogRead(PIEZZO_PIN);
- if (piezzoValue > 10)
- {
- if (millis() - lastUpdate > 1000)
- {
- r = random(255);
- g = random(255);
- b = random(255);
- lastUpdate = millis();
- }
- piezzoValue = map(piezzoValue, 64, 512, 16, 225);
- FastLED.setBrightness(piezzoValue);
- }
- else
- {
- r = g = b = 0;
- FastLED.setBrightness(0);
- }
- fillLED();
- delay(50);
- }
- void fillLED()
- {
- for (uint8_t i = 0; i < NUM_LEDS; i++)
- {
- leds[i].r = r;
- leds[i].g = g;
- leds[i].b = b;
- }
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement