Advertisement
pleasedontcode

LED Control rev_01

May 1st, 2024
140
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: 2024-05-01 08:29:43
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The LED chipset is WS2812B RGB  Number of LED is */
  21.     /* 20  Digital output is D5  write a code:  led fade */
  22.     /* in and out randomly, increments 5.  set fade in */
  23.     /* value at 0,  set fade out value at 255  set fade */
  24.     /* time from 0 to 255 at 5 seconds  use only warm */
  25.     /* colors */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <FastLED.h>    //https://github.com/FastLED/FastLED
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35. void ledFadeInOut(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t WS2812B_LEDRGB_PIN_D5 = 5; // Digital output pin D5 for WS2812B LED
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. CRGB leds[20]; // Define LED array with 20 LEDs
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.     FastLED.addLeds<WS2812B, WS2812B_LEDRGB_PIN_D5, GRB>(leds, 20); // Initialize FastLED object with 20 LEDs on pin D5
  47.  
  48.     pinMode(WS2812B_LEDRGB_PIN_D5, OUTPUT); // Set D5 pin as output
  49. }
  50.  
  51. void loop(void)
  52. {
  53.     // put your main code here, to run repeatedly:
  54.     updateOutputs(); // Refresh output data
  55.     ledFadeInOut(); // Perform LED fade in and out randomly
  56. }
  57.  
  58. void updateOutputs()
  59. {
  60.     // No need to update outputs in this case
  61. }
  62.  
  63. void ledFadeInOut()
  64. {
  65.     static uint8_t fadeValue = 0;
  66.     static bool fadeDirection = true;
  67.  
  68.     if (fadeDirection) {
  69.         fadeValue += 5;
  70.         if (fadeValue >= 255) {
  71.             fadeDirection = false;
  72.         }
  73.     } else {
  74.         fadeValue -= 5;
  75.         if (fadeValue <= 0) {
  76.             fadeDirection = true;
  77.         }
  78.     }
  79.  
  80.     // Set warm color based on fade value
  81.     CRGB color = CRGB(fadeValue, fadeValue * 0.7, fadeValue * 0.3);
  82.  
  83.     // Set LED color
  84.     for (int i = 0; i < 20; i++) {
  85.         leds[i] = color;
  86.     }
  87.  
  88.     // Show LED color
  89.     FastLED.show();
  90.  
  91.     // Delay for 5 seconds
  92.     delay(5000);
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement