CCCPaste

"FastLED Animation" rev_09

/********* 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: "FastLED Animation"
	- Source Code NOT compiled for: Arduino Mega
	- Source Code created on: 2024-06-11 22:35:07

********* 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  //https://github.com/FastLED/FastLED

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void fadeall(CRGB* leds, int numLeds);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t led_P9813_DIN_PIN_D2 = 2;
const uint8_t led_P9813_CIN_PIN_D3 = 3;
const uint8_t led_SK9822_DIN_PIN_D6 = 6;
const uint8_t led_SK9822_CIN_PIN_D7 = 7;

/***** 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;
bool led_SK9822_DIN_PIN_D6_rawData = 0;
bool led_SK9822_CIN_PIN_D7_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;
float led_SK9822_DIN_PIN_D6_phyData = 0.0;
float led_SK9822_CIN_PIN_D7_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
#define NUM_LEDS_P9813 64
#define NUM_LEDS_SK9822 64

CRGB leds_P9813[NUM_LEDS_P9813];
CRGB leds_SK9822[NUM_LEDS_SK9822];

void setup(void)
{
    // Initialize digital pins for output
    pinMode(led_P9813_DIN_PIN_D2, OUTPUT);
    pinMode(led_P9813_CIN_PIN_D3, OUTPUT);
    pinMode(led_SK9822_DIN_PIN_D6, OUTPUT);
    pinMode(led_SK9822_CIN_PIN_D7, OUTPUT);

    // Initialize FastLED for P9813
    FastLED.addLeds(leds_P9813, NUM_LEDS_P9813);
    FastLED.setBrightness(84);

    // Initialize FastLED for SK9822
    FastLED.addLeds(leds_SK9822, NUM_LEDS_SK9822);
    FastLED.setBrightness(84);
}

void loop(void)
{
    // Refresh output data
    updateOutputs();

    // Supercar effect for P9813
    static uint8_t hue_P9813 = 0;
    for (int i = 0; i < NUM_LEDS_P9813; i++) {
        leds_P9813[i] = CHSV(hue_P9813++, 255, 255);
        FastLED.show();
        fadeall(leds_P9813, NUM_LEDS_P9813);
        delay(10);
    }
    for (int i = NUM_LEDS_P9813 - 1; i >= 0; i--) {
        leds_P9813[i] = CHSV(hue_P9813++, 255, 255);
        FastLED.show();
        fadeall(leds_P9813, NUM_LEDS_P9813);
        delay(10);
    }

    // Supercar effect for SK9822
    static uint8_t hue_SK9822 = 0;
    for (int i = 0; i < NUM_LEDS_SK9822; i++) {
        leds_SK9822[i] = CHSV(hue_SK9822++, 255, 255);
        FastLED.show();
        fadeall(leds_SK9822, NUM_LEDS_SK9822);
        delay(10);
    }
    for (int i = NUM_LEDS_SK9822 - 1; i >= 0; i--) {
        leds_SK9822[i] = CHSV(hue_SK9822++, 255, 255);
        FastLED.show();
        fadeall(leds_SK9822, NUM_LEDS_SK9822);
        delay(10);
    }
}

void updateOutputs()
{
    digitalWrite(led_P9813_DIN_PIN_D2, led_P9813_DIN_PIN_D2_rawData);
    digitalWrite(led_P9813_CIN_PIN_D3, led_P9813_CIN_PIN_D3_rawData);
    digitalWrite(led_SK9822_DIN_PIN_D6, led_SK9822_DIN_PIN_D6_rawData);
    digitalWrite(led_SK9822_CIN_PIN_D7, led_SK9822_CIN_PIN_D7_rawData);
}

void fadeall(CRGB* leds, int numLeds) {
    for (int i = 0; i < numLeds; i++) {
        leds[i].nscale8(250);
    }
}

/* END CODE */