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 Controller
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-07-06 21:34:20
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement an LED strip control system using the */
- /* FastLED library on an Arduino Uno, including */
- /* functions for color changing, brightness */
- /* adjustment, and pattern display. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h>
- // Define the number of LEDs
- #define NUM_LEDS 60
- // Define the data pin (change as needed)
- #define DATA_PIN 6
- // Create LED array
- CRGB leds[NUM_LEDS];
- // Variables for brightness and pattern
- uint8_t currentBrightness = 128;
- uint8_t currentPattern = 0;
- // Pattern functions
- void patternRainbow() {
- fill_rainbow(leds, NUM_LEDS, currentPattern * 8, 7);
- }
- void patternStripe() {
- for (int i = 0; i < NUM_LEDS; i++) {
- if (i % 2 == 0) {
- leds[i] = CRGB::Red;
- } else {
- leds[i] = CRGB::Blue;
- }
- }
- }
- void patternFade() {
- fadeToBlackBy(leds, NUM_LEDS, 10);
- leds[currentPattern * 5 % NUM_LEDS] = CRGB::White;
- }
- // Function prototypes for color and brightness control
- void setColor(CRGB color);
- void changePattern();
- void adjustBrightness(uint8_t brightness);
- /// Function to set the entire strip to a specific color
- void setColor(CRGB color) {
- fill_solid(leds, NUM_LEDS, color);
- FastLED.show();
- }
- /// Function to change to the next pattern
- void changePattern() {
- currentPattern = (currentPattern + 1) % 3;
- switch (currentPattern) {
- case 0:
- patternRainbow();
- break;
- case 1:
- patternStripe();
- break;
- case 2:
- patternFade();
- break;
- }
- }
- /// Function to adjust brightness
- void adjustBrightness(uint8_t brightness) {
- currentBrightness = brightness;
- FastLED.setBrightness(currentBrightness);
- }
- void setup() {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Initialize LED strip
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- // Set initial pattern
- patternRainbow();
- // Set initial brightness
- FastLED.setBrightness(currentBrightness);
- }
- void loop() {
- // Example usage:
- // Change pattern every 10 seconds
- static uint32_t lastChangeTime = 0;
- if (millis() - lastChangeTime > 10000) {
- changePattern();
- lastChangeTime = millis();
- }
- // Adjust brightness with serial input (if available)
- if (Serial.available()) {
- char cmd = Serial.read();
- if (cmd == 'u') {
- // increase brightness
- uint8_t new_brightness = constrain(FastLED.getBrightness() + 10, 0, 255);
- adjustBrightness(new_brightness);
- } else if (cmd == 'd') {
- // decrease brightness
- uint8_t new_brightness = constrain(FastLED.getBrightness() - 10, 0, 255);
- adjustBrightness(new_brightness);
- } else if (cmd == 'c') {
- // change color randomly
- setColor(CRGB::Green);
- }
- }
- // Repeat current pattern
- if (currentPattern == 0) {
- patternRainbow();
- } else if (currentPattern == 1) {
- patternStripe();
- } else if (currentPattern == 2) {
- patternFade();
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement