Advertisement
microrobotics

Adafruit Ultra High Density DotStar LED PCB Bar with 128 LEDs

May 9th, 2023
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To use the Adafruit Ultra High Density DotStar LED PCB Bar with 128 LEDs, you will need the Adafruit DotStar library. You can install the library using the Arduino Library Manager by searching for "Adafruit DotStar" and installing the latest version.
  3.  
  4. This code will create a color chase animation with red, green, and blue colors on the DotStar LED PCB Bar with 128 LEDs.
  5.  
  6. Before uploading the code to your Arduino, make sure to wire the DotStar LED PCB Bar correctly:
  7.  
  8. Connect the 5V pin of the DotStar LED PCB Bar to the 5V pin on the Arduino.
  9. Connect the GND pin of the DotStar LED PCB Bar to the GND pin on the Arduino.
  10. Connect the CI (Clock Input) pin of the DotStar LED PCB Bar to the clock pin (SCK) on the Arduino. In this example, we are using pin 5.
  11. Connect the DI (Data Input) pin of the DotStar LED PCB Bar to the data pin (MOSI) on the Arduino. In this example, we are using pin 4.
  12. Upload the code to your Arduino, and you should see the color chase animation on the DotStar LED PCB Bar. You can customize the colors and animation speed by modifying the colorChase() function calls in the loop() function.
  13. */
  14.  
  15. #include <Adafruit_DotStar.h>
  16. #include <SPI.h> // Needed for hardware SPI
  17.  
  18. #define NUMPIXELS 128 // Number of LEDs on the PCB Bar
  19. #define DATAPIN    4  // Data pin (MOSI) connected to the DotStar strip
  20. #define CLOCKPIN   5  // Clock pin (SCK) connected to the DotStar strip
  21.  
  22. // Initialize the DotStar strip using hardware SPI
  23. Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
  24.  
  25. void setup() {
  26.   strip.begin(); // Initialize the DotStar strip
  27.   strip.show();  // Turn off all the LEDs (they might be on from the start)
  28. }
  29.  
  30. void loop() {
  31.   // Run a simple color chase animation
  32.   colorChase(strip.Color(255, 0, 0), 50); // Red
  33.   colorChase(strip.Color(0, 255, 0), 50); // Green
  34.   colorChase(strip.Color(0, 0, 255), 50); // Blue
  35. }
  36.  
  37. // Function to run a color chase animation
  38. void colorChase(uint32_t color, uint8_t wait) {
  39.   for (int i = 0; i < strip.numPixels(); i++) {
  40.     strip.setPixelColor(i, color); // Set the color for the current pixel
  41.     strip.show();                  // Display the updated colors on the strip
  42.     strip.setPixelColor(i, 0);     // Clear the color for the current pixel
  43.     delay(wait);                   // Pause before moving to the next pixel
  44.   }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement