Advertisement
pleasedontcode

"Supercar Animation" rev_07

Jun 11th, 2024
399
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 Animation"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 22:02:55
  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 <SPI.h>
  29. #include <FastLED.h>  // https://github.com/FastLED/FastLED
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void fadeall(void);
  35.  
  36. /***** DEFINITION OF SPI PINS *****/
  37. const uint8_t led_P9813_SPI_PIN_MOSI_D51 = 51;
  38. const uint8_t led_P9813_SPI_PIN_MISO_D50 = 50;
  39. const uint8_t led_P9813_SPI_PIN_SCLK_D52 = 52;
  40. const uint8_t led_P9813_SPI_PIN_CS_D53 = 53;
  41.  
  42. /****** DEFINITION OF LED STRIP PARAMETERS *****/
  43. #define NUM_LEDS 64
  44. #define DATA_PIN 2
  45. #define CLOCK_PIN 13
  46.  
  47. /****** DEFINITION OF LED ARRAY *****/
  48. CRGB leds[NUM_LEDS];
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. // FastLED instance is globally available as FastLED
  52.  
  53. void setup(void)
  54. {
  55.     // Set the data pin as output
  56.     pinMode(DATA_PIN, OUTPUT);
  57.     // Initialize the SPI library
  58.     SPI.begin();
  59.  
  60.     // Initialize the FastLED library
  61.     FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  62.     FastLED.setBrightness(84);  // Set brightness level
  63. }
  64.  
  65. void loop(void)
  66. {
  67.     // Implement the supercar effect
  68.     static uint8_t hue = 0;
  69.     for (int i = 0; i < NUM_LEDS; i++) {
  70.         leds[i] = CHSV(hue++, 255, 255);
  71.         FastLED.show();
  72.         fadeall();
  73.         delay(10);
  74.     }
  75.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  76.         leds[i] = CHSV(hue++, 255, 255);
  77.         FastLED.show();
  78.         fadeall();
  79.         delay(10);
  80.     }
  81. }
  82.  
  83. void fadeall() {
  84.     for (int i = 0; i < NUM_LEDS; i++) {
  85.         leds[i].nscale8(250);
  86.     }
  87. }
  88.  
  89. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement