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: "LED Control"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-04-30 05:09:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* We use the FastLED library. The task is to */
- /* smoothly turn on and off the WS2812b LED strip, */
- /* which has 240 LEDs, we need the ability to adjust */
- /* the brightness and temperature of the glow, */
- /* connected to the D13 pin. Turning on and off is */
- /* done by pressing */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void turnOnLEDs();
- void turnOffLEDs();
- void adjustBrightness(uint8_t brightness);
- void adjustTemperature(uint8_t temperature);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Constants
- #define NUM_LEDS 240
- #define DATA_PIN 13
- // Create an array of CRGB to hold the LED colors
- CRGB leds[NUM_LEDS];
- // Variables to hold brightness and temperature
- uint8_t brightness = 255; // Max brightness
- uint8_t temperature = 0; // Default temperature
- // Button state
- bool ledState = false; // LED state (on/off)
- void setup(void)
- {
- // Initialize FastLED
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- FastLED.setBrightness(brightness);
- }
- void loop(void)
- {
- // Check for button press to toggle LED state
- if (/* condition to check button press */) {
- ledState = !ledState; // Toggle LED state
- if (ledState) {
- turnOnLEDs();
- } else {
- turnOffLEDs();
- }
- }
- // Update the LED strip
- FastLED.show();
- }
- // Function to turn on LEDs with a smooth transition
- void turnOnLEDs() {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CRGB::White; // Set color to white
- FastLED.setBrightness(brightness);
- FastLED.show();
- delay(10); // Delay for smooth transition
- }
- }
- // Function to turn off LEDs with a smooth transition
- void turnOffLEDs() {
- for (int i = NUM_LEDS - 1; i >= 0; i--) {
- leds[i] = CRGB::Black; // Set color to black
- FastLED.setBrightness(brightness);
- FastLED.show();
- delay(10); // Delay for smooth transition
- }
- }
- // Function to adjust brightness
- void adjustBrightness(uint8_t newBrightness) {
- brightness = newBrightness;
- FastLED.setBrightness(brightness);
- }
- // Function to adjust temperature (for color temperature adjustment)
- void adjustTemperature(uint8_t newTemperature) {
- temperature = newTemperature;
- // Implement temperature adjustment logic here if needed
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement