Advertisement
pleasedontcode

Warm Glow rev_04

May 1st, 2024
90
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: Warm Glow
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-01 09:31:48
  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.  
  29. /********* User code review feedback **********
  30. #### Feedback 1 ####
  31. - The colors for each led are random, use warm colors only
  32. #### Feedback 2 ####
  33. - the 20 led fade in and out at the same time. this should not be.
  34.  each single led should fade in and out separately and randomly
  35. ********* User code review feedback **********/
  36.  
  37. /****** DEFINITION OF LIBRARIES *****/
  38. #include <FastLED.h>    //https://github.com/FastLED/FastLED
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void updateOutputs(void);
  44. void ledFadeInOut(void);
  45.  
  46. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  47. const uint8_t WS2812B_LEDRGB_PIN_D5 = 5; // Digital output pin D5 for WS2812B LED
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. CRGB leds[20]; // Define LED array with 20 LEDs
  51.  
  52. void setup(void)
  53. {
  54.     // put your setup code here, to run once:
  55.     FastLED.addLeds<WS2812B, WS2812B_LEDRGB_PIN_D5, GRB>(leds, 20); // Initialize FastLED object with 20 LEDs on pin D5
  56.  
  57.     pinMode(WS2812B_LEDRGB_PIN_D5, OUTPUT); // Set D5 pin as output
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // put your main code here, to run repeatedly:
  63.     updateOutputs(); // Refresh output data
  64.     ledFadeInOut(); // Perform LED fade in and out randomly
  65. }
  66.  
  67. void updateOutputs()
  68. {
  69.     // No need to update outputs in this case
  70. }
  71.  
  72. void ledFadeInOut()
  73. {
  74.     static uint8_t fadeValues[20] = {0}; // Array to store fade values for each LED
  75.     static bool fadeDirections[20] = {true}; // Array to store fade directions for each LED
  76.  
  77.     for (int i = 0; i < 20; i++) {
  78.         if (fadeDirections[i]) {
  79.             fadeValues[i] += 5;
  80.             if (fadeValues[i] >= 255) {
  81.                 fadeDirections[i] = false;
  82.             }
  83.         } else {
  84.             fadeValues[i] -= 5;
  85.             if (fadeValues[i] <= 0) {
  86.                 fadeDirections[i] = true;
  87.             }
  88.         }
  89.  
  90.         // Set warm color based on fade value for each LED
  91.         CRGB color = CRGB(fadeValues[i], fadeValues[i] * 0.7, fadeValues[i] * 0.3);
  92.  
  93.         // Set LED color
  94.         leds[i] = color;
  95.     }
  96.  
  97.     // Show LED colors
  98.     FastLED.show();
  99. }
  100.  
  101. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement