Advertisement
pleasedontcode

"LED Control" rev_01

Jun 11th, 2024
439
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 Mega
  14.     - Source Code created on: 2024-06-11 13:54:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a supercar effect using WS2812B LED */
  21.     /* strip controlled by FastLED library. The setup */
  22.     /* involves initializing digital pin 2 for output and */
  23.     /* continuously updating the LED state based on raw */
  24.     /* data input. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <FastLED.h> //https://github.com/FastLED/FastLED
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34. void fadeall(void);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. /***** used to store raw data *****/
  41. bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. /***** used to store data after characteristic curve transformation *****/
  45. float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
  46.  
  47. /****** DEFINITION OF LED STRIP PARAMETERS *****/
  48. #define NUM_LEDS 64 // Number of LEDs in the strip
  49. #define DATA_PIN strip_WS2812B_DIN_PIN_D2 // Data pin for the LED strip
  50.  
  51. /****** DEFINITION OF LED ARRAY *****/
  52. CRGB leds[NUM_LEDS]; // Array to hold LED color data
  53.  
  54. void setup(void) {
  55.     // Initialize the LED strip
  56.     FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  57.     FastLED.setBrightness(84); // Set brightness level
  58.  
  59.     // Initialize the data pin
  60.     pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
  61. }
  62.  
  63. void loop(void) {
  64.     // Update the LED pattern
  65.     static uint8_t hue = 0;
  66.     for (int i = 0; i < NUM_LEDS; i++) {
  67.         leds[i] = CHSV(hue++, 255, 255); // Set LED color
  68.         FastLED.show(); // Update the LEDs
  69.         fadeall(); // Fade all LEDs
  70.         delay(10); // Delay for smooth animation
  71.     }
  72.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  73.         leds[i] = CHSV(hue++, 255, 255); // Set LED color
  74.         FastLED.show(); // Update the LEDs
  75.         fadeall(); // Fade all LEDs
  76.         delay(10); // Delay for smooth animation
  77.     }
  78.  
  79.     // Refresh output data
  80.     updateOutputs();
  81. }
  82.  
  83. void updateOutputs() {
  84.     // Update the digital output pin with raw data
  85.     digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
  86. }
  87.  
  88. void fadeall() {
  89.     // Reduce brightness of all LEDs
  90.     for (int i = 0; i < NUM_LEDS; i++) {
  91.         leds[i].nscale8(250);
  92.     }
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement