Advertisement
pleasedontcode

"Supercar LEDs" rev_05

Jun 11th, 2024
246
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 LEDs"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 14:13:16
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a supercar effect using WS2812_B 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. /****** 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.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. /***** used to store data after characteristic curve transformation *****/
  44. float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. // Number of LEDs in the strip
  48. #define NUM_LEDS 60
  49.  
  50. // Array of LEDs
  51. CRGB leds[NUM_LEDS];
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.  
  57.     pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
  58.  
  59.     // Initialize the LED strip
  60.     FastLED.addLeds<WS2812B, strip_WS2812B_DIN_PIN_D2, GRB>(leds, NUM_LEDS);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.  
  67.     updateOutputs(); // Refresh output data
  68.  
  69.     // Supercar effect: Move a single red LED back and forth along the strip
  70.     for (int i = 0; i < NUM_LEDS; i++) {
  71.         leds[i] = CRGB::Red;
  72.         FastLED.show();
  73.         delay(30);
  74.         leds[i] = CRGB::Black;
  75.     }
  76.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  77.         leds[i] = CRGB::Red;
  78.         FastLED.show();
  79.         delay(30);
  80.         leds[i] = CRGB::Black;
  81.     }
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.     digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
  87. }
  88.  
  89. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement