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: 2024-05-01 08:29:43
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The LED chipset is WS2812B RGB Number of LED is */
- /* 20 Digital output is D5 write a code: led fade */
- /* in and out randomly, increments 5. set fade in */
- /* value at 0, set fade out value at 255 set fade */
- /* time from 0 to 255 at 5 seconds use only warm */
- /* colors */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void ledFadeInOut(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t WS2812B_LEDRGB_PIN_D5 = 5; // Digital output pin D5 for WS2812B LED
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- CRGB leds[20]; // Define LED array with 20 LEDs
- void setup(void)
- {
- // put your setup code here, to run once:
- FastLED.addLeds<WS2812B, WS2812B_LEDRGB_PIN_D5, GRB>(leds, 20); // Initialize FastLED object with 20 LEDs on pin D5
- pinMode(WS2812B_LEDRGB_PIN_D5, OUTPUT); // Set D5 pin as output
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- ledFadeInOut(); // Perform LED fade in and out randomly
- }
- void updateOutputs()
- {
- // No need to update outputs in this case
- }
- void ledFadeInOut()
- {
- static uint8_t fadeValue = 0;
- static bool fadeDirection = true;
- if (fadeDirection) {
- fadeValue += 5;
- if (fadeValue >= 255) {
- fadeDirection = false;
- }
- } else {
- fadeValue -= 5;
- if (fadeValue <= 0) {
- fadeDirection = true;
- }
- }
- // Set warm color based on fade value
- CRGB color = CRGB(fadeValue, fadeValue * 0.7, fadeValue * 0.3);
- // Set LED color
- for (int i = 0; i < 20; i++) {
- leds[i] = color;
- }
- // Show LED color
- FastLED.show();
- // Delay for 5 seconds
- delay(5000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement