Advertisement
pleasedontcode

"FastLED Animation" rev_10

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