Advertisement
pleasedontcode

"LED Control" rev_03

Jun 11th, 2024
328
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 14:00:25
  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. /********* User code review feedback **********
  29. #### Feedback 1 ####
  30. - number of led on strip are 9
  31. ********* User code review feedback **********/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <FastLED.h> //https://github.com/FastLED/FastLED
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39. void updateOutputs(void);
  40. void fadeall(void);
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
  52.  
  53. /****** DEFINITION OF LED STRIP PARAMETERS *****/
  54. #define NUM_LEDS 9 // Number of LEDs in the strip
  55. #define DATA_PIN strip_WS2812B_DIN_PIN_D2 // Data pin for the LED strip
  56.  
  57. /****** DEFINITION OF LED ARRAY *****/
  58. CRGB leds[NUM_LEDS]; // Array to hold LED color data
  59.  
  60. void setup(void) {
  61.     // Initialize the LED strip
  62.     FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  63.     FastLED.setBrightness(84); // Set brightness level
  64.  
  65.     // Initialize the data pin
  66.     pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
  67. }
  68.  
  69. void loop(void) {
  70.     // Update the LED pattern
  71.     static uint8_t hue = 0;
  72.     for (int i = 0; i < NUM_LEDS; 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.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  79.         leds[i] = CHSV(hue++, 255, 255); // Set LED color
  80.         FastLED.show(); // Update the LEDs
  81.         fadeall(); // Fade all LEDs
  82.         delay(10); // Delay for smooth animation
  83.     }
  84.  
  85.     // Refresh output data
  86.     updateOutputs();
  87. }
  88.  
  89. void updateOutputs() {
  90.     // Update the digital output pin with raw data
  91.     digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
  92. }
  93.  
  94. void fadeall() {
  95.     // Reduce brightness of all LEDs
  96.     for (int i = 0; i < NUM_LEDS; i++) {
  97.         leds[i].nscale8(250);
  98.     }
  99. }
  100.  
  101. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement