Advertisement
pleasedontcode

"LED Control" rev_01

Apr 30th, 2025
170
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:09:51
  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.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void turnOnLEDs();
  37. void turnOffLEDs();
  38. void adjustBrightness(uint8_t brightness);
  39. void adjustTemperature(uint8_t temperature);
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  42.  
  43. // Constants
  44. #define NUM_LEDS 240
  45. #define DATA_PIN 13
  46.  
  47. // Create an array of CRGB to hold the LED colors
  48. CRGB leds[NUM_LEDS];
  49.  
  50. // Variables to hold brightness and temperature
  51. uint8_t brightness = 255; // Max brightness
  52. uint8_t temperature = 0; // Default temperature
  53.  
  54. // Button state
  55. bool ledState = false; // LED state (on/off)
  56.  
  57. void setup(void)
  58. {
  59.     // Initialize FastLED
  60.     FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  61.     FastLED.setBrightness(brightness);
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // Check for button press to toggle LED state
  67.     if (/* condition to check button press */) {
  68.         ledState = !ledState; // Toggle LED state
  69.         if (ledState) {
  70.             turnOnLEDs();
  71.         } else {
  72.             turnOffLEDs();
  73.         }
  74.     }
  75.  
  76.     // Update the LED strip
  77.     FastLED.show();
  78. }
  79.  
  80. // Function to turn on LEDs with a smooth transition
  81. void turnOnLEDs() {
  82.     for (int i = 0; i < NUM_LEDS; i++) {
  83.         leds[i] = CRGB::White; // Set color to white
  84.         FastLED.setBrightness(brightness);
  85.         FastLED.show();
  86.         delay(10); // Delay for smooth transition
  87.     }
  88. }
  89.  
  90. // Function to turn off LEDs with a smooth transition
  91. void turnOffLEDs() {
  92.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  93.         leds[i] = CRGB::Black; // Set color to black
  94.         FastLED.setBrightness(brightness);
  95.         FastLED.show();
  96.         delay(10); // Delay for smooth transition
  97.     }
  98. }
  99.  
  100. // Function to adjust brightness
  101. void adjustBrightness(uint8_t newBrightness) {
  102.     brightness = newBrightness;
  103.     FastLED.setBrightness(brightness);
  104. }
  105.  
  106. // Function to adjust temperature (for color temperature adjustment)
  107. void adjustTemperature(uint8_t newTemperature) {
  108.     temperature = newTemperature;
  109.     // Implement temperature adjustment logic here if needed
  110. }
  111.  
  112. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement