Advertisement
pleasedontcode

"Supercar LED" rev_08

Jun 11th, 2024
437
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: "Supercar LED"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 22:09:10
  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(void);
  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.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool led_P9813_DIN_PIN_D2_rawData = 0;
  43. bool led_P9813_CIN_PIN_D3_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float led_P9813_DIN_PIN_D2_phyData = 0.0;
  48. float led_P9813_CIN_PIN_D3_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LED STRIP PARAMETERS *****/
  51. #define NUM_LEDS 64
  52. #define DATA_PIN 2
  53. #define CLOCK_PIN 3
  54.  
  55. /****** DEFINITION OF LED ARRAY *****/
  56. CRGB leds[NUM_LEDS];
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59.  
  60. /****** SETUP FUNCTION *****/
  61. void setup(void)
  62. {
  63.     // Initialize the FastLED library for the P9813 chipset
  64.     FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  65.     FastLED.setBrightness(84); // Set brightness to a moderate level
  66.  
  67.     // Initialize other pins
  68.     pinMode(led_P9813_DIN_PIN_D2, OUTPUT);
  69.     pinMode(led_P9813_CIN_PIN_D3, OUTPUT);
  70. }
  71.  
  72. /****** LOOP FUNCTION *****/
  73. void loop(void)
  74. {
  75.     // Refresh output data
  76.     updateOutputs();
  77.  
  78.     // Supercar effect (Cylon effect)
  79.     static uint8_t hue = 0;
  80.     for (int i = 0; i < NUM_LEDS; i++) {
  81.         leds[i] = CHSV(hue++, 255, 255);
  82.         FastLED.show();
  83.         fadeall();
  84.         delay(10);
  85.     }
  86.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  87.         leds[i] = CHSV(hue++, 255, 255);
  88.         FastLED.show();
  89.         fadeall();
  90.         delay(10);
  91.     }
  92. }
  93.  
  94. /****** UPDATE OUTPUTS FUNCTION *****/
  95. void updateOutputs()
  96. {
  97.     // Update digital outputs based on raw data
  98.     digitalWrite(led_P9813_DIN_PIN_D2, led_P9813_DIN_PIN_D2_rawData);
  99.     digitalWrite(led_P9813_CIN_PIN_D3, led_P9813_CIN_PIN_D3_rawData);
  100. }
  101.  
  102. /****** FADEALL FUNCTION *****/
  103. // Function to gradually reduce the brightness of all LEDs
  104. void fadeall() {
  105.     for (int i = 0; i < NUM_LEDS; i++) {
  106.         leds[i].nscale8(250);
  107.     }
  108. }
  109.  
  110. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement