Advertisement
microrobotics

WS2812B LED TH Diffused

May 4th, 2023
2,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here is a basic example of Arduino code for controlling multiple WS2812B LED's with the help of the FastLED library. This code will create a simple color cycle effect. Please ensure you have the FastLED library installed before uploading this code to your Arduino.
  3.  
  4. For connecting the WS2812B LED strip with DIN, VDD, GND, and DOUT pins to your Arduino, please follow these steps:
  5.  
  6. Connect the VDD pin on the LED strip to a 5V power supply (not the Arduino 5V pin, as it might not be able to supply enough current for the LED strip). Make sure the power supply can provide enough current for the number of LEDs you are using.
  7.  
  8. Connect the GND pin on the LED strip to the ground of the 5V power supply and the ground of your Arduino.
  9.  
  10. Connect the DIN pin on the LED strip to the data pin defined in the code (pin 6 in the example).
  11.  
  12. The DOUT pin is used to connect to the DIN pin of another LED strip if you want to extend your setup. You don't need to connect this pin to the Arduino.
  13.  
  14. After making these connections, upload the provided code to your Arduino, and it should work as expected with the color cycle effect.
  15.  
  16. This code initializes the FastLED library and creates an array to represent the WS2812B LEDs. It then sets up a loop that updates the colors of the LEDs based on a changing hue value, resulting in a color cycle effect. The brightness is set to 50 (out of 255) to ensure the LEDs don't get too hot or draw too much current.
  17.  
  18. You can modify this code to create custom effects or respond to external inputs.
  19. */
  20.  
  21. #include <FastLED.h>
  22.  
  23. // Define the number of LEDs and the data pin
  24. #define NUM_LEDS 30
  25. #define DATA_PIN 6
  26.  
  27. // Declare the LED array and the FastLED controller
  28. CRGB leds[NUM_LEDS];
  29. int hue = 0;
  30.  
  31. void setup() {
  32.   // Initialize the FastLED library
  33.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  34.   FastLED.setBrightness(50);
  35. }
  36.  
  37. void loop() {
  38.   // Color cycle effect
  39.   for (int i = 0; i < NUM_LEDS; i++) {
  40.     leds[i] = CHSV(hue, 255, 255);
  41.   }
  42.  
  43.   // Update the LED strip with the new colors
  44.   FastLED.show();
  45.  
  46.   // Increase the hue value for the next cycle
  47.   hue++;
  48.  
  49.   // Wait for a moment before the next update
  50.   FastLED.delay(30);
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement