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: Arduino Uno
- - Source Code created on: 2025-04-30 05:13:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* We use the FastLED library. The task is to */
- /* smoothly turn on and off the WS2812b LED strip, */
- /* which has 240 LEDs, we need the ability to adjust */
- /* the brightness and temperature of the glow, */
- /* connected to the D13 pin. Turning on and off is */
- /* done by pressing */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void toggleLED(); // Function to toggle LED on and off
- void adjustBrightness(); // Function to adjust brightness
- void adjustTemperature(); // Function to adjust temperature
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Button1_PushButton_PIN_D2 = 2;
- /***** LED STRIP CONFIGURATION *****/
- #define NUM_LEDS 240
- #define DATA_PIN 13
- CRGB leds[NUM_LEDS]; // Array to hold LED colors
- EasyButton button(Button1_PushButton_PIN_D2); // Button instance
- // Variables for brightness and temperature
- uint8_t brightness = 255; // Full brightness
- uint8_t temperature = 0; // Default temperature
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Button1_PushButton_PIN_D2, INPUT_PULLUP);
- // Initialize the button
- button.begin();
- // Initialize the LED strip
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- FastLED.setBrightness(brightness);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.read(); // Read button state
- // Check if the button is pressed
- if (button.pressed()) {
- toggleLED(); // Toggle LED on button press
- }
- // Adjust brightness and temperature if needed
- adjustBrightness();
- adjustTemperature();
- // Show the LEDs with the current settings
- FastLED.show();
- }
- // Function to toggle LED on and off
- void toggleLED() {
- static bool ledState = false; // Track LED state
- ledState = !ledState; // Toggle state
- if (ledState) {
- // Turn on LEDs with current brightness and temperature
- fill_solid(leds, NUM_LEDS, CHSV(temperature, 255, brightness));
- } else {
- // Turn off LEDs
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- }
- }
- // Function to adjust brightness (placeholder for actual implementation)
- void adjustBrightness() {
- // Example: Adjust brightness based on some condition or input
- // This can be expanded to use a potentiometer or other input method
- }
- // Function to adjust temperature (placeholder for actual implementation)
- void adjustTemperature() {
- // Example: Adjust temperature based on some condition or input
- // This can be expanded to use a potentiometer or other input method
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement