Advertisement
pleasedontcode

"LED Control" rev_02

Jun 11th, 2024
310
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 compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 13:59:24
  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.  
  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 fadeall(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
  47.  
  48. /****** DEFINITION OF LED STRIP PARAMETERS *****/
  49. #define NUM_LEDS 64 // Number of LEDs in the strip
  50. #define DATA_PIN strip_WS2812B_DIN_PIN_D2 // Data pin for the LED strip
  51.  
  52. /****** DEFINITION OF LED ARRAY *****/
  53. CRGB leds[NUM_LEDS]; // Array to hold LED color data
  54.  
  55. void setup(void) {
  56.     // Initialize the LED strip
  57.     FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  58.     FastLED.setBrightness(84); // Set brightness level
  59.  
  60.     // Initialize the data pin
  61.     pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
  62. }
  63.  
  64. void loop(void) {
  65.     // Update the LED pattern
  66.     static uint8_t hue = 0;
  67.     for (int i = 0; i < NUM_LEDS; i++) {
  68.         leds[i] = CHSV(hue++, 255, 255); // Set LED color
  69.         FastLED.show(); // Update the LEDs
  70.         fadeall(); // Fade all LEDs
  71.         delay(10); // Delay for smooth animation
  72.     }
  73.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  74.         leds[i] = CHSV(hue++, 255, 255); // Set LED color
  75.         FastLED.show(); // Update the LEDs
  76.         fadeall(); // Fade all LEDs
  77.         delay(10); // Delay for smooth animation
  78.     }
  79.  
  80.     // Refresh output data
  81.     updateOutputs();
  82. }
  83.  
  84. void updateOutputs() {
  85.     // Update the digital output pin with raw data
  86.     digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
  87. }
  88.  
  89. void fadeall() {
  90.     // Reduce brightness of all LEDs
  91.     for (int i = 0; i < NUM_LEDS; i++) {
  92.         leds[i].nscale8(250);
  93.     }
  94. }
  95.  
  96. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement