/********* 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: "LED Control"
- Source Code NOT compiled for: Arduino Mega
- Source Code created on: 2024-06-11 14:00:25
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Implement a supercar effect using WS2812B 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 *****/
/********* User code review feedback **********
#### Feedback 1 ####
- number of led on strip are 9
********* User code review feedback **********/
/****** DEFINITION OF LIBRARIES *****/
#include //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 strip_WS2812B_DIN_PIN_D2 = 2;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
/****** DEFINITION OF LED STRIP PARAMETERS *****/
#define NUM_LEDS 9 // Number of LEDs in the strip
#define DATA_PIN strip_WS2812B_DIN_PIN_D2 // Data pin for the LED strip
/****** DEFINITION OF LED ARRAY *****/
CRGB leds[NUM_LEDS]; // Array to hold LED color data
void setup(void) {
// Initialize the LED strip
FastLED.addLeds(leds, NUM_LEDS);
FastLED.setBrightness(84); // Set brightness level
// Initialize the data pin
pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
}
void loop(void) {
// Update the LED pattern
static uint8_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue++, 255, 255); // Set LED color
FastLED.show(); // Update the LEDs
fadeall(); // Fade all LEDs
delay(10); // Delay for smooth animation
}
for (int i = NUM_LEDS - 1; i >= 0; i--) {
leds[i] = CHSV(hue++, 255, 255); // Set LED color
FastLED.show(); // Update the LEDs
fadeall(); // Fade all LEDs
delay(10); // Delay for smooth animation
}
// Refresh output data
updateOutputs();
}
void updateOutputs() {
// Update the digital output pin with raw data
digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
}
void fadeall() {
// Reduce brightness of all LEDs
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(250);
}
}
/* END CODE */