Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **LED Control**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-04-06 20:32:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* WRITE A CODE FOR ESP32 USING FASTLED CLOCKLESS IN */
- /* ESPHOME TO CONTROL TWO LED STRIP FROM 2 INPUT */
- /* BOOLEAN IN HOME ASSISTANT WHEN BUTTON 1 IS PRESSED */
- /* THE STRIP ONE WILL HAVE EFFECT WIPE FROM LAST TO */
- /* FIRST LED AND AFTER THAT STRIP 2 HAVE THE WIPE */
- /* EFFECT */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- // Include necessary libraries for ESP32 and FastLED
- #include <FastLED.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void wipeEffect(CRGB *leds, int numLeds, CRGB color);
- /****** GLOBAL VARIABLES *****/
- #define NUM_LEDS1 30 // Number of LEDs in strip 1
- #define NUM_LEDS2 30 // Number of LEDs in strip 2
- CRGB leds1[NUM_LEDS1]; // Array for strip 1
- CRGB leds2[NUM_LEDS2]; // Array for strip 2
- // Define button pin
- const int buttonPin = 2; // Pin where the button is connected
- bool lastButtonState = LOW; // Previous state of the button
- void setup(void)
- {
- // put your setup code here, to run once:
- // Initialize FastLED
- FastLED.addLeds<WS2812B, 18, GRB>(leds1, NUM_LEDS1);
- FastLED.addLeds<WS2812B, 19, GRB>(leds2, NUM_LEDS2);
- // Initialize button pin
- pinMode(buttonPin, INPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- bool currentButtonState = digitalRead(buttonPin);
- // Check if button is pressed
- if (currentButtonState == HIGH && lastButtonState == LOW) {
- // Wipe effect on strip 1
- wipeEffect(leds1, NUM_LEDS1, CRGB::Red); // Change color as needed
- FastLED.show();
- delay(500); // Delay to see the effect
- // Wipe effect on strip 2
- wipeEffect(leds2, NUM_LEDS2, CRGB::Blue); // Change color as needed
- FastLED.show();
- }
- lastButtonState = currentButtonState; // Update button state
- }
- void wipeEffect(CRGB *leds, int numLeds, CRGB color) {
- // Wipe effect from last to first LED
- for (int i = numLeds - 1; i >= 0; i--) {
- leds[i] = color; // Set LED color
- FastLED.show();
- delay(50); // Delay for effect
- leds[i] = CRGB::Black; // Turn off LED after wipe
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement