Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Supercar LED"
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-06-11 22:09:10
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a supercar effect using LED strip */
- /* controlled by FastLED library. The setup involves */
- /* initializing digital pin 2 for output and */
- /* continuously updating the LED state based on raw */
- /* data input. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> // https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void fadeall(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t led_P9813_DIN_PIN_D2 = 2;
- const uint8_t led_P9813_CIN_PIN_D3 = 3;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool led_P9813_DIN_PIN_D2_rawData = 0;
- bool led_P9813_CIN_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float led_P9813_DIN_PIN_D2_phyData = 0.0;
- float led_P9813_CIN_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LED STRIP PARAMETERS *****/
- #define NUM_LEDS 64
- #define DATA_PIN 2
- #define CLOCK_PIN 3
- /****** DEFINITION OF LED ARRAY *****/
- CRGB leds[NUM_LEDS];
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Initialize the FastLED library for the P9813 chipset
- FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- FastLED.setBrightness(84); // Set brightness to a moderate level
- // Initialize other pins
- pinMode(led_P9813_DIN_PIN_D2, OUTPUT);
- pinMode(led_P9813_CIN_PIN_D3, OUTPUT);
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Refresh output data
- updateOutputs();
- // Supercar effect (Cylon effect)
- static uint8_t hue = 0;
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(10);
- }
- for (int i = NUM_LEDS - 1; i >= 0; i--) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(10);
- }
- }
- /****** UPDATE OUTPUTS FUNCTION *****/
- void updateOutputs()
- {
- // Update digital outputs based on raw data
- digitalWrite(led_P9813_DIN_PIN_D2, led_P9813_DIN_PIN_D2_rawData);
- digitalWrite(led_P9813_CIN_PIN_D3, led_P9813_CIN_PIN_D3_rawData);
- }
- /****** FADEALL FUNCTION *****/
- // Function to gradually reduce the brightness of all LEDs
- void fadeall() {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].nscale8(250);
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement