Advertisement
pleasedontcode

FastLED Control rev_09

May 4th, 2024
792
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: FastLED Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-04 09:30:50
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* output d5  number of led 20  ws2812B RGB  use */
  21.     /* random color  fade in and out in 10 seconds */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* output d5  ws2812B  number of LED 20  each LED */
  24.     /* random color  use 256 colors  each LED random */
  25.     /* brightness from 0 to 255  each LED fading in and */
  26.     /* out random speed */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <FastLED.h>  // https://github.com/FastLED/FastLED
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36. void randomFadeInOut(void);
  37. void randomFadingLEDs(void);
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t LED_PIN_D5 = 5;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. bool LED_PIN_D5_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. float LED_PIN_D5_phyData = 0.0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. #define NUM_LEDS 20
  50. #define DATA_PIN 5
  51. #define BRIGHTNESS 50
  52.  
  53. CRGB leds[NUM_LEDS];
  54. FastLED_NeoPixel_Variant strip(leds, NUM_LEDS);
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     pinMode(LED_PIN_D5, OUTPUT);
  60.  
  61.     strip.begin(FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS));
  62.     strip.setBrightness(BRIGHTNESS);
  63. }
  64.  
  65. void loop(void)
  66. {
  67.     // put your main code here, to run repeatedly:
  68.     randomFadeInOut(); // System Requirement 1
  69.     randomFadingLEDs(); // System Requirement 2
  70.     updateOutputs(); // Refresh output data
  71. }
  72.  
  73. void updateOutputs(void)
  74. {
  75.     digitalWrite(LED_PIN_D5, LED_PIN_D5_rawData);
  76. }
  77.  
  78. void randomFadeInOut(void)
  79. {
  80.     // Random color fade in and out in 10 seconds for LED connected to D5
  81.     // Implement the code for System Requirement 1 here
  82.     for (int i = 0; i < 256; i++) {
  83.         uint8_t brightness = i;
  84.         leds[0] = CHSV(random8(), 255, brightness);
  85.         FastLED.show();
  86.         delay(40);
  87.     }
  88.     for (int i = 255; i >= 0; i--) {
  89.         uint8_t brightness = i;
  90.         leds[0] = CHSV(random8(), 255, brightness);
  91.         FastLED.show();
  92.         delay(40);
  93.     }
  94. }
  95.  
  96. void randomFadingLEDs(void)
  97. {
  98.     // Random color, brightness, and fading in and out for each LED connected to D5
  99.     // Implement the code for System Requirement 2 here
  100.     for (int i = 0; i < NUM_LEDS; i++) {
  101.         uint8_t brightness = random8();
  102.         leds[i] = CHSV(random8(), 255, brightness);
  103.     }
  104.     FastLED.show();
  105.     delay(random(100, 1000));
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement