Arduino NeoPixel Rainbow | Black Lives Matter Education ...

Skip to main content Black Lives Matter Education & Workshop Kit Arduino NeoPixel Rainbow
  • Overview
  • Guided Tour
  • CircuitPython
    • Blink
    • Sound Reactive NeoPixels
    • Capacitive Touch
  • Arduino IDE Setup
    • Using with Arduino IDE
    • Adapting Sketches to M0 & M4
    • Arduino Blink
    • Arduino NeoPixel Rainbow
  • Downloads
  • Single page
  • Feedback? Corrections?
  • Text View
Primary Products
  • Your browser does not support the video tag. Video of a rotating Black Lives Matter Education & Workshop Kit. Black Lives Matter Education & Workshop Kit Out of Stock
5 Beginner Product guide

Arduino NeoPixel Rainbow

The BLM Badge comes with six side-lit NeoPixel LEDs around the edge of the board. These RGB NeoPixel LEDs can be used to create all the colors of the rainbow and everything in between. The following example displays a flowing rainbow across all the LEDs.

NeoPixel

You'll need to install one library in Arduino for this example to work. Open the Arduino IDE. Click Arduino > Sketch > Include library... > Manage Libraries, then type 'neopixel' in the search box. Install the library shown here.

adafruit_products_Arduino_NeoPixel_library.png

Code

In the Arduino IDE, create a new sketch by clicking  File > New

Then, copy the code shown below and paste it into the new sketch.

Download File Copy Code #include <Adafruit_NeoPixel.h> #define LED_COUNT 6 #define LED_PIN PIN_NEOPIXEL Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); strip.show(); strip.setBrightness(50); } void loop() { rainbow(10); } void rainbow(int wait) { for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) { for(int i=0; i<strip.numPixels(); i++) { int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); } strip.show(); delay(wait); } } #include <Adafruit_NeoPixel.h> #define LED_COUNT 6 #define LED_PIN PIN_NEOPIXEL Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); strip.show(); strip.setBrightness(50); } void loop() { rainbow(10); } void rainbow(int wait) { for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) { for(int i=0; i<strip.numPixels(); i++) { int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); } strip.show(); delay(wait); } }

Rainbows!

First you include the NeoPixel library you installed.

Next, you tell the code you have 6 NeoPixels, and the pin they are on. Then, you declare the NeoPixel object using the info you provided.

In setup, you initialise the NeoPixel strip object, make sure the LEDs begin turned off, and set the brightness to approximately 1/5 maximum (max is 255). These LEDs are really bright at max!

In the loop, we run the rainbow code with a 10ms delay. Increase this number to slow down the rainbow.

Finally, we have the rainbow code, which requires you to provide a wait time in milliseconds.

That's all there is to making NeoPixel rainbows with Arduino and the BLM badge!

Page last edited March 08, 2024

Text editor powered by tinymce.

Arduino Blink Downloads Related Guides Navi10 MacroPad with KB2040 and KMK CircuitPython... By Eva Herrada beginner HalloWing Interactive Cat Toy By Dave Astels intermediate Control Wiz Lights With CircuitPython By Tim C beginner Adafruit PiUART - USB Console and Power Add-on for... By lady ada beginner Adafruit Metro M4 Express featuring ATSAMD51 By lady ada beginner Adafruit SHT31-D Temperature & Humidity Sensor Breakout By lady ada intermediate Bluetooth TV Zapper By John Park beginner Adafruit A4988 Stepper Motor Driver Breakout Board By Liz Clark beginner Adafruit Rotary Trinkey By Kattni Rembor beginner Theme Park Wait Time Display By Ruiz Brothers beginner Your browser does not support the video tag. This links to the guide Dune Worm Thumper. Dune Worm Thumper By Ruiz Brothers beginner 3D Printed LED Knuckle Jewelry By Ruiz Brothers beginner Your browser does not support the video tag. This links to the guide 3D-Printed Bionic Eye. 3D-Printed Bionic Eye By Bill Earl beginner Adafruit RFM69HCW and RFM9X LoRa Packet Radio Breakouts By lady ada intermediate Ladyada's Toolkit By Erin St Blaine beginner
Create Wishlist
× Title Description Close Search Search
Categories

Tag » Arduino Rgb Led Strip Rainbow Code