Advertisement
Guest User

Untitled

a guest
Apr 15th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <FastLED.h>
  2. #define NUM_LEDS 60
  3. #define LED_PIN 17
  4. CRGB leds[NUM_LEDS];
  5.  
  6. #define BUTTON1_PIN 1
  7. #define BUTTON2_PIN 18
  8. #define BUTTON3_PIN 3
  9. #define BUTTON4_PIN 5
  10. #define BUTTON5_PIN 19
  11.  
  12. unsigned long countdownTime = 0;
  13. unsigned long startTime = 0;
  14.  
  15. void setup() {
  16. FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  17. pinMode(BUTTON1_PIN, INPUT_PULLUP);
  18. pinMode(BUTTON2_PIN, INPUT_PULLUP);
  19. pinMode(BUTTON3_PIN, INPUT_PULLUP);
  20. pinMode(BUTTON4_PIN, INPUT_PULLUP);
  21. pinMode(BUTTON5_PIN, INPUT_PULLUP);
  22. }
  23.  
  24. void loop() {
  25. if (millis() < 5000) {
  26. if (digitalRead(BUTTON1_PIN) == LOW) countdownTime += 3600;
  27. if (digitalRead(BUTTON2_PIN) == LOW) countdownTime += 600;
  28. if (digitalRead(BUTTON3_PIN) == LOW) countdownTime += 60;
  29. if (digitalRead(BUTTON4_PIN) == LOW) countdownTime += 10;
  30. if (digitalRead(BUTTON5_PIN) == LOW) countdownTime += 1;
  31. FastLED.showColor(CRGB::Green);
  32. } else {
  33. int ledToTurnOff = map(millis() - 5000, 0, countdownTime/60 * 1000 , 0, NUM_LEDS);
  34. for (int i = 0; i < NUM_LEDS; i++) {
  35. if (i < ledToTurnOff) {
  36. leds[i] = CRGB::Black;
  37. } else {
  38. leds[i] = CRGB::Red;
  39. }
  40. }
  41. FastLED.show();
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement