Guest User

tv code

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