LED Shield Guide & Example Code

LED Shield Guide & Example Code

Our new LED Shield is designed to make using NeoPixel and DotStar LED strips and rings as easy as possible with controllers that use the Arduino Uno pinout. The screw terminal connectors mean you don't need to fuss with connectors, simply strip the wires and screw them into place. We've tested it with our range of LED Strips, Rings & Matrixes but it'll work with any LEDs that are compatible with Arduino and use the same connections.


Shield Overview


Located on towards the bottom of the shield are two pushbuttons labelled BTN1 and BTN2. When the shield is attached to an microcontroller these are connected to D2 and D3 respectivley. When the button is pressed 5V will be present at the data pin, the data pin will be connected to GND. These buttons are perfect for changing between patterns or turning the LEDs on/off.



In the centre of the board are two potentiometers with plastic knobs pre-attched, POT1 and POT2. These are connected to analogue pins A1 and A0 and when used as inputs provide a value between 0 and 1023 thanks to the Unos 10-bit ADC.


DotStar Connections:

Connect your DotStar compatible LED strips, ring and matrices to these terminal connectors. There are four labelled connections DIN, CLK, V+ and GND. DIN is connected to D4, CLK is connected to D5 and GND is connected to the microcontrollers ground. V+ will change between an external supply and the connected controllers supply depending on the posistion of the power supply switch this is detailed in the Power Source Switch section below.


NeoPixel Connections:

This connector is for use with all NeoPixel compatible LED devices. It has three labelled connections, DIN, V+ and GND. DIN is connected to D6 and GND is connected to the microcontrollers ground. Like with the DotStar connectors the V+ will depend on the status of the power supply switch.



External Power Connections:

This connector is used to connect external power supplys for powering the LED devices. When powered via USB or the barrel jack the boards power supply on an Arduino Uno can typically supply ~200mA. This is fine if you're using a 1m LED strip or LED ring but if you're using a longer strip you'll need more power.

This connector allows you to power the LEDs with a beefier power supply while also ensuring there is a common ground between the external power supply and the controller. If you use an external power supply you will also need to ensure the controller connected is also powered via it's own connections as this connector purely supplys power to the LEDs.



 Power Source Switch:

This switch is used to determine which way the LEDs are powered. If you are using an external power supply connected via the Power terminal connector then ensure the switch is in the VEXT position. Otherwise ensure it is in the VINT position to power the LEDs from the connected controller.


Example Code

We've created some simple example code to demonstrate how the various inputs on the LED Shield can be used. You can download the Arduino INO file here, the code is based on Adafruit's buttoncycle example uses the Adafruit NeoPixel library so you'll need to ensure you have that installed for the code to work as expected.

The code uses a button as an input to cycle through LED colours and one of the potentiometers to control the brighness of the LED patterns. The comments in the code below should help to illustrate how it works and what is happening.

 #include Adafruit_NeoPixel.h

#define BUTTON_PIN 2
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 24 // Number of NeoPixels

int BRIGHTVAL = 0; // Variable to store birghness value in
const int POT1 = A1; // Analogue input for Potentiometer 1 on the shield
int Pot1Value = 0; // value read from the pot

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9

void setup() {
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'

void loop() {
// Get current button state.
Pot1Value = analogRead(POT1); //Stores input potentiometer value in variable
BRIGHTVAL = map(Pot1Value, 0, 1023, 0, 255); //Changes input into value between 0 & 255
boolean newState = digitalRead(BUTTON_PIN);

// Check if state changed from high to low (button press).
if((newState == LOW) && (oldState == HIGH)) {
// Short delay to debounce button.
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if(newState == LOW) { // Yes, still low
if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation... case 0: colorWipe(strip.Color( 0, 0, 0), 50); // Black/off break; case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red break; case 2: colorWipe(strip.Color( 0, 255, 0), 50); // Green break; case 3: colorWipe(strip.Color( 0, 0, 255), 50); // Blue break; case 4: colorWipe(strip.Color( 252, 240, 3), 50); // Yellow break; case 5: colorWipe(strip.Color( 152, 3, 252), 50); // Purple break; case 6: colorWipe(strip.Color( 252, 3, 219), 50); // Pink break; } } } // Set the last-read button state to the old state. oldState = newState; } void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.setBrightness(BRIGHTVAL); // Set brightness value between 0-255
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
Previous Next