Advertisement
pleasedontcode

LED Controller rev_01

Jul 6th, 2025
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: LED Controller
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-07-06 21:34:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement an LED strip control system using the */
  21.     /* FastLED library on an Arduino Uno, including */
  22.     /* functions for color changing, brightness */
  23.     /* adjustment, and pattern display. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <FastLED.h>
  29.  
  30. // Define the number of LEDs
  31. #define NUM_LEDS 60
  32. // Define the data pin (change as needed)
  33. #define DATA_PIN 6
  34.  
  35. // Create LED array
  36. CRGB leds[NUM_LEDS];
  37.  
  38. // Variables for brightness and pattern
  39. uint8_t currentBrightness = 128;
  40. uint8_t currentPattern = 0;
  41.  
  42. // Pattern functions
  43. void patternRainbow() {
  44.   fill_rainbow(leds, NUM_LEDS, currentPattern * 8, 7);
  45. }
  46.  
  47. void patternStripe() {
  48.   for (int i = 0; i < NUM_LEDS; i++) {
  49.     if (i % 2 == 0) {
  50.       leds[i] = CRGB::Red;
  51.     } else {
  52.       leds[i] = CRGB::Blue;
  53.     }
  54.   }
  55. }
  56.  
  57. void patternFade() {
  58.   fadeToBlackBy(leds, NUM_LEDS, 10);
  59.   leds[currentPattern * 5 % NUM_LEDS] = CRGB::White;
  60. }
  61.  
  62. // Function prototypes for color and brightness control
  63. void setColor(CRGB color);
  64. void changePattern();
  65. void adjustBrightness(uint8_t brightness);
  66.  
  67. /// Function to set the entire strip to a specific color
  68. void setColor(CRGB color) {
  69.   fill_solid(leds, NUM_LEDS, color);
  70.   FastLED.show();
  71. }
  72.  
  73. /// Function to change to the next pattern
  74. void changePattern() {
  75.   currentPattern = (currentPattern + 1) % 3;
  76.   switch (currentPattern) {
  77.     case 0:
  78.       patternRainbow();
  79.       break;
  80.     case 1:
  81.       patternStripe();
  82.       break;
  83.     case 2:
  84.       patternFade();
  85.       break;
  86.   }
  87. }
  88.  
  89. /// Function to adjust brightness
  90. void adjustBrightness(uint8_t brightness) {
  91.   currentBrightness = brightness;
  92.   FastLED.setBrightness(currentBrightness);
  93. }
  94.  
  95. void setup() {
  96.   // Initialize serial communication for debugging
  97.   Serial.begin(9600);
  98.   // Initialize LED strip
  99.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  100.   // Set initial pattern
  101.   patternRainbow();
  102.   // Set initial brightness
  103.   FastLED.setBrightness(currentBrightness);
  104. }
  105.  
  106. void loop() {
  107.   // Example usage:
  108.  
  109.   // Change pattern every 10 seconds
  110.   static uint32_t lastChangeTime = 0;
  111.   if (millis() - lastChangeTime > 10000) {
  112.     changePattern();
  113.     lastChangeTime = millis();
  114.   }
  115.  
  116.   // Adjust brightness with serial input (if available)
  117.   if (Serial.available()) {
  118.     char cmd = Serial.read();
  119.     if (cmd == 'u') {
  120.       // increase brightness
  121.       uint8_t new_brightness = constrain(FastLED.getBrightness() + 10, 0, 255);
  122.       adjustBrightness(new_brightness);
  123.     } else if (cmd == 'd') {
  124.       // decrease brightness
  125.       uint8_t new_brightness = constrain(FastLED.getBrightness() - 10, 0, 255);
  126.       adjustBrightness(new_brightness);
  127.     } else if (cmd == 'c') {
  128.       // change color randomly
  129.       setColor(CRGB::Green);
  130.     }
  131.   }
  132.  
  133.   // Repeat current pattern
  134.   if (currentPattern == 0) {
  135.     patternRainbow();
  136.   } else if (currentPattern == 1) {
  137.     patternStripe();
  138.   } else if (currentPattern == 2) {
  139.     patternFade();
  140.   }
  141.  
  142.   delay(100);
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement