Advertisement
pleasedontcode

"FastLED Animation" rev_09

Jun 11th, 2024
376
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: "FastLED Animation"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 22:35:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a supercar effect using LED strip */
  21.     /* controlled by FastLED library. The setup involves */
  22.     /* 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(CRGB* leds, int numLeds);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t led_P9813_DIN_PIN_D2 = 2;
  38. const uint8_t led_P9813_CIN_PIN_D3 = 3;
  39. const uint8_t led_SK9822_DIN_PIN_D6 = 6;
  40. const uint8_t led_SK9822_CIN_PIN_D7 = 7;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool led_P9813_DIN_PIN_D2_rawData = 0;
  45. bool led_P9813_CIN_PIN_D3_rawData = 0;
  46. bool led_SK9822_DIN_PIN_D6_rawData = 0;
  47. bool led_SK9822_CIN_PIN_D7_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float led_P9813_DIN_PIN_D2_phyData = 0.0;
  52. float led_P9813_CIN_PIN_D3_phyData = 0.0;
  53. float led_SK9822_DIN_PIN_D6_phyData = 0.0;
  54. float led_SK9822_CIN_PIN_D7_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. #define NUM_LEDS_P9813 64
  58. #define NUM_LEDS_SK9822 64
  59.  
  60. CRGB leds_P9813[NUM_LEDS_P9813];
  61. CRGB leds_SK9822[NUM_LEDS_SK9822];
  62.  
  63. void setup(void)
  64. {
  65.     // Initialize digital pins for output
  66.     pinMode(led_P9813_DIN_PIN_D2, OUTPUT);
  67.     pinMode(led_P9813_CIN_PIN_D3, OUTPUT);
  68.     pinMode(led_SK9822_DIN_PIN_D6, OUTPUT);
  69.     pinMode(led_SK9822_CIN_PIN_D7, OUTPUT);
  70.  
  71.     // Initialize FastLED for P9813
  72.     FastLED.addLeds<P9813, led_P9813_DIN_PIN_D2, led_P9813_CIN_PIN_D3, RGB>(leds_P9813, NUM_LEDS_P9813);
  73.     FastLED.setBrightness(84);
  74.  
  75.     // Initialize FastLED for SK9822
  76.     FastLED.addLeds<SK9822, led_SK9822_DIN_PIN_D6, led_SK9822_CIN_PIN_D7, RGB>(leds_SK9822, NUM_LEDS_SK9822);
  77.     FastLED.setBrightness(84);
  78. }
  79.  
  80. void loop(void)
  81. {
  82.     // Refresh output data
  83.     updateOutputs();
  84.  
  85.     // Supercar effect for P9813
  86.     static uint8_t hue_P9813 = 0;
  87.     for (int i = 0; i < NUM_LEDS_P9813; i++) {
  88.         leds_P9813[i] = CHSV(hue_P9813++, 255, 255);
  89.         FastLED.show();
  90.         fadeall(leds_P9813, NUM_LEDS_P9813);
  91.         delay(10);
  92.     }
  93.     for (int i = NUM_LEDS_P9813 - 1; i >= 0; i--) {
  94.         leds_P9813[i] = CHSV(hue_P9813++, 255, 255);
  95.         FastLED.show();
  96.         fadeall(leds_P9813, NUM_LEDS_P9813);
  97.         delay(10);
  98.     }
  99.  
  100.     // Supercar effect for SK9822
  101.     static uint8_t hue_SK9822 = 0;
  102.     for (int i = 0; i < NUM_LEDS_SK9822; i++) {
  103.         leds_SK9822[i] = CHSV(hue_SK9822++, 255, 255);
  104.         FastLED.show();
  105.         fadeall(leds_SK9822, NUM_LEDS_SK9822);
  106.         delay(10);
  107.     }
  108.     for (int i = NUM_LEDS_SK9822 - 1; i >= 0; i--) {
  109.         leds_SK9822[i] = CHSV(hue_SK9822++, 255, 255);
  110.         FastLED.show();
  111.         fadeall(leds_SK9822, NUM_LEDS_SK9822);
  112.         delay(10);
  113.     }
  114. }
  115.  
  116. void updateOutputs()
  117. {
  118.     digitalWrite(led_P9813_DIN_PIN_D2, led_P9813_DIN_PIN_D2_rawData);
  119.     digitalWrite(led_P9813_CIN_PIN_D3, led_P9813_CIN_PIN_D3_rawData);
  120.     digitalWrite(led_SK9822_DIN_PIN_D6, led_SK9822_DIN_PIN_D6_rawData);
  121.     digitalWrite(led_SK9822_CIN_PIN_D7, led_SK9822_CIN_PIN_D7_rawData);
  122. }
  123.  
  124. void fadeall(CRGB* leds, int numLeds) {
  125.     for (int i = 0; i < numLeds; i++) {
  126.         leds[i].nscale8(250);
  127.     }
  128. }
  129.  
  130. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement