Advertisement
pleasedontcode

**LED Control** rev_02

Apr 30th, 2025
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **LED Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-30 05:13:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* We use the FastLED library. The task is to */
  21.     /* smoothly turn on and off the WS2812b LED strip, */
  22.     /* which has 240 LEDs, we need the ability to adjust */
  23.     /* the brightness and temperature of the glow, */
  24.     /* connected to the D13 pin. Turning on and off is */
  25.     /* done by pressing */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <FastLED.h>    //https://github.com/FastLED/FastLED
  32. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void toggleLED(); // Function to toggle LED on and off
  38. void adjustBrightness(); // Function to adjust brightness
  39. void adjustTemperature(); // Function to adjust temperature
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t Button1_PushButton_PIN_D2 = 2;
  43.  
  44. /***** LED STRIP CONFIGURATION *****/
  45. #define NUM_LEDS 240
  46. #define DATA_PIN 13
  47. CRGB leds[NUM_LEDS]; // Array to hold LED colors
  48. EasyButton button(Button1_PushButton_PIN_D2); // Button instance
  49.  
  50. // Variables for brightness and temperature
  51. uint8_t brightness = 255; // Full brightness
  52. uint8_t temperature = 0; // Default temperature
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     pinMode(Button1_PushButton_PIN_D2, INPUT_PULLUP);
  60.    
  61.     // Initialize the button
  62.     button.begin();
  63.    
  64.     // Initialize the LED strip
  65.     FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  66.     FastLED.setBrightness(brightness);
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // put your main code here, to run repeatedly:
  72.     button.read(); // Read button state
  73.  
  74.     // Check if the button is pressed
  75.     if (button.pressed()) {
  76.         toggleLED(); // Toggle LED on button press
  77.     }
  78.  
  79.     // Adjust brightness and temperature if needed
  80.     adjustBrightness();
  81.     adjustTemperature();
  82.  
  83.     // Show the LEDs with the current settings
  84.     FastLED.show();
  85. }
  86.  
  87. // Function to toggle LED on and off
  88. void toggleLED() {
  89.     static bool ledState = false; // Track LED state
  90.     ledState = !ledState; // Toggle state
  91.     if (ledState) {
  92.         // Turn on LEDs with current brightness and temperature
  93.         fill_solid(leds, NUM_LEDS, CHSV(temperature, 255, brightness));
  94.     } else {
  95.         // Turn off LEDs
  96.         fill_solid(leds, NUM_LEDS, CRGB::Black);
  97.     }
  98. }
  99.  
  100. // Function to adjust brightness (placeholder for actual implementation)
  101. void adjustBrightness() {
  102.     // Example: Adjust brightness based on some condition or input
  103.     // This can be expanded to use a potentiometer or other input method
  104. }
  105.  
  106. // Function to adjust temperature (placeholder for actual implementation)
  107. void adjustTemperature() {
  108.     // Example: Adjust temperature based on some condition or input
  109.     // This can be expanded to use a potentiometer or other input method
  110. }
  111.  
  112. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement