Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int BUTTON_PIN = 7;
- const int LED_PIN = 6;
- const int TV_PIN = 3;
- #include <FastLED.h>
- #define num_leds 16
- #define pin 6
- CRGB leds[num_leds];
- int ledState = LOW;
- int lastButtonState;
- int currentButtonState;
- void setup() {
- Serial.begin(9600);
- pinMode(BUTTON_PIN, INPUT);
- pinMode(TV_PIN, OUTPUT);
- pinMode(LED_PIN, OUTPUT);
- FastLED.addLeds<WS2812B, pin, GRB>(leds, num_leds);
- FastLED.setBrightness(100);
- currentButtonState = digitalRead(BUTTON_PIN);
- }
- void loop() {
- lastButtonState = currentButtonState;
- currentButtonState = digitalRead(BUTTON_PIN);
- if (lastButtonState == HIGH && currentButtonState == LOW) {
- Serial.print("The button is pressed: ");
- if (ledState == LOW) {
- ledState = HIGH;
- Serial.println("Turning LED on");
- } else {
- ledState = LOW;
- Serial.println("Turning LED off");
- }
- digitalWrite(TV_PIN, ledState);
- }
- if (ledState == LOW) {
- fill_solid(leds, num_leds, CRGB(0, 0, 0));
- } else {
- fill_solid(leds, num_leds, CRGB(255, 255, 255));
- }
- ledState = ledState;
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment