Guest User

Untitled

a guest
Dec 7th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2. const int BUTTON_PIN = 7;
  3. const int LED_PIN = 6;
  4. const int TV_PIN = 3;
  5. #include <FastLED.h>
  6. #define num_leds 16
  7. #define pin 6
  8.  
  9. CRGB leds[num_leds];
  10.  
  11. int ledState = LOW;
  12. int lastButtonState;
  13. int currentButtonState;
  14.  
  15. void setup() {
  16. Serial.begin(9600);
  17. pinMode(BUTTON_PIN, INPUT);
  18. pinMode(TV_PIN, OUTPUT);
  19. pinMode(LED_PIN, OUTPUT);
  20. FastLED.addLeds<WS2812B, pin, GRB>(leds, num_leds);
  21. FastLED.setBrightness(100);
  22.  
  23.  
  24. currentButtonState = digitalRead(BUTTON_PIN);
  25. }
  26.  
  27. void loop() {
  28. lastButtonState = currentButtonState;
  29. currentButtonState = digitalRead(BUTTON_PIN);
  30.  
  31. if (lastButtonState == HIGH && currentButtonState == LOW) {
  32. Serial.print("The button is pressed: ");
  33.  
  34. if (ledState == LOW) {
  35. ledState = HIGH;
  36. Serial.println("Turning LED on");
  37.  
  38. } else {
  39. ledState = LOW;
  40. Serial.println("Turning LED off");
  41. }
  42.  
  43. digitalWrite(TV_PIN, ledState);
  44. }
  45. if (ledState == LOW) {
  46. fill_solid(leds, num_leds, CRGB(0, 0, 0));
  47. } else {
  48. fill_solid(leds, num_leds, CRGB(255, 255, 255));
  49. }
  50. ledState = ledState;
  51. FastLED.show();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment