Skip to content

Commit

Permalink
0_simpleExamples
Browse files Browse the repository at this point in the history
Add very simple examples to show basic use of the library.
  • Loading branch information
sonyhome committed Jan 27, 2017
1 parent 2a88eaf commit 9a4d5df
Show file tree
Hide file tree
Showing 12 changed files with 1,011 additions and 8 deletions.
108 changes: 108 additions & 0 deletions Examples/0_simpleExamples/apa102/apa102.ino
@@ -0,0 +1,108 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Fast Adressable Bitbang LED Library
/// Copyright (c)2015, 2017 Dan Truong
///
/// This is the simplest exmple to use the library.
///
/// This example is for an Arduino Uno board with a LED strip connected to
/// port D5-D6. Targetting any other board requires you to change something.
/// The program sends an array of pixels to display on the strip.
/// "strip" represents the hardware: LED types and port configuration,
/// "pixels" represents the data sent to the LEDs: a series of colors.
///
/// Wiring:
///
/// The LED strip DI (data input) line should be on port D6 (Digital pin 6 on
/// Arduino Uno). The LED strip CI (clock input) should be on port D5 (Digital
/// pin 5). If you need to change the port, change all declarations below
/// from, for example from "apa102<D,6,D,4> strip" to "apa102<B,4,B,3> strip"
/// if you wanted to use port B3-B4.
/// The LED power (GND) and (+5V) should be connected on the Arduino Uno's GND
/// and +5V.
///
/// Visual results:
///
/// If the hardware you use matches this program you will see the LEDs blink
/// repeatedly red, green, blue, white, in that order.
///
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

#include <FAB_LED.h>

// Declare the LED protocol and the port
apa102<D,6,D,5> strip;

// How many pixels to control
const uint8_t numPixels = 2;

// How bright the LEDs will be (max 255)
const uint8_t maxBrightness = 16;

// The pixel array to display
hbgr pixels[numPixels] = {};


////////////////////////////////////////////////////////////////////////////////
// Sets the array to specified color
////////////////////////////////////////////////////////////////////////////////
void updateColors(char r, char g, char b)
{
for(int i = 0; i < numPixels; i++)
{
pixels[i].h = 0xFF;
pixels[i].r = r;
pixels[i].g = g;
pixels[i].b = b;
}
}

////////////////////////////////////////////////////////////////////////////////
// This method is automatically called once when the board boots.
////////////////////////////////////////////////////////////////////////////////
void setup()
{
// Turn off the LEDs
strip.clear(2 * numPixels);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief This method is automatically called repeatedly after setup() has run.
/// It is the main loop.
////////////////////////////////////////////////////////////////////////////////
void loop()
{

// Write the pixel array red
updateColors(maxBrightness, 0 , 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array green
updateColors(0, maxBrightness, 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array blue
updateColors(0, 0, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array white
updateColors( maxBrightness, maxBrightness, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Turn off the LEDs
strip.clear(numPixels);
delay(600);
}
106 changes: 106 additions & 0 deletions Examples/0_simpleExamples/apa104/apa104.ino
@@ -0,0 +1,106 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Fast Adressable Bitbang LED Library
/// Copyright (c)2015, 2017 Dan Truong
///
/// This is the simplest exmple to use the library.
///
/// This example is for an Arduino Uno board with a LED strip connected to
/// port D6. Targetting any other board requires you to change something.
/// The program sends an array of pixels to display on the strip.
/// "strip" represents the hardware: LED types and port configuration,
/// "pixels" represents the data sent to the LEDs: a series of colors.
///
/// Wiring:
///
/// The LED strip DI (data input) line should be on port D6 (Digital pin 6 on
/// Arduino Uno). If you need to change the port, change all declarations below
/// from, for example from "ws2812b<D,6> myWs2812" to "ws2812b<B,4> myWs2812"
/// if you wanted to use port B4.
/// The LED power (GND) and (+5V) should be connected on the Arduino Uno's GND
/// and +5V.
///
/// Visual results:
///
/// If the hardware you use matches this program you will see the LEDs blink
/// repeatedly red, green, blue, white, in that order.
///
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

#include <FAB_LED.h>

// Declare the LED protocol and the port
apa104<D,6> strip;

// How many pixels to control
const uint8_t numPixels = 2;

// How bright the LEDs will be (max 255)
const uint8_t maxBrightness = 16;

// The pixel array to display
grb pixels[numPixels] = {};


////////////////////////////////////////////////////////////////////////////////
// Sets the array to specified color
////////////////////////////////////////////////////////////////////////////////
void updateColors(char r, char g, char b)
{
for(int i = 0; i < numPixels; i++)
{
pixels[i].r = r;
pixels[i].g = g;
pixels[i].b = b;
}
}

////////////////////////////////////////////////////////////////////////////////
// This method is automatically called once when the board boots.
////////////////////////////////////////////////////////////////////////////////
void setup()
{
// Turn off the LEDs
strip.clear(2 * numPixels);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief This method is automatically called repeatedly after setup() has run.
/// It is the main loop.
////////////////////////////////////////////////////////////////////////////////
void loop()
{

// Write the pixel array red
updateColors(maxBrightness, 0 , 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array green
updateColors(0, maxBrightness, 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array blue
updateColors(0, 0, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array white
updateColors( maxBrightness, maxBrightness, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Turn off the LEDs
strip.clear(numPixels);
delay(600);
}
106 changes: 106 additions & 0 deletions Examples/0_simpleExamples/apa106/apa106.ino
@@ -0,0 +1,106 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Fast Adressable Bitbang LED Library
/// Copyright (c)2015, 2017 Dan Truong
///
/// This is the simplest exmple to use the library.
///
/// This example is for an Arduino Uno board with a LED strip connected to
/// port D6. Targetting any other board requires you to change something.
/// The program sends an array of pixels to display on the strip.
/// "strip" represents the hardware: LED types and port configuration,
/// "pixels" represents the data sent to the LEDs: a series of colors.
///
/// Wiring:
///
/// The LED strip DI (data input) line should be on port D6 (Digital pin 6 on
/// Arduino Uno). If you need to change the port, change all declarations below
/// from, for example from "ws2812b<D,6> myWs2812" to "ws2812b<B,4> myWs2812"
/// if you wanted to use port B4.
/// The LED power (GND) and (+5V) should be connected on the Arduino Uno's GND
/// and +5V.
///
/// Visual results:
///
/// If the hardware you use matches this program you will see the LEDs blink
/// repeatedly red, green, blue, white, in that order.
///
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

#include <FAB_LED.h>

// Declare the LED protocol and the port
apa106<D,6> strip;

// How many pixels to control
const uint8_t numPixels = 2;

// How bright the LEDs will be (max 255)
const uint8_t maxBrightness = 16;

// The pixel array to display
rgb pixels[numPixels] = {};


////////////////////////////////////////////////////////////////////////////////
// Sets the array to specified color
////////////////////////////////////////////////////////////////////////////////
void updateColors(char r, char g, char b)
{
for(int i = 0; i < numPixels; i++)
{
pixels[i].r = r;
pixels[i].g = g;
pixels[i].b = b;
}
}

////////////////////////////////////////////////////////////////////////////////
// This method is automatically called once when the board boots.
////////////////////////////////////////////////////////////////////////////////
void setup()
{
// Turn off the LEDs
strip.clear(2 * numPixels);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief This method is automatically called repeatedly after setup() has run.
/// It is the main loop.
////////////////////////////////////////////////////////////////////////////////
void loop()
{

// Write the pixel array red
updateColors(maxBrightness, 0 , 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array green
updateColors(0, maxBrightness, 0);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array blue
updateColors(0, 0, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Write the pixel array white
updateColors( maxBrightness, maxBrightness, maxBrightness);
// Display the pixels on the LED strip
strip.sendPixels(numPixels, pixels);
// Wait 0.1 seconds
delay(100);

// Turn off the LEDs
strip.clear(numPixels);
delay(600);
}
20 changes: 20 additions & 0 deletions Examples/0_simpleExamples/readme.txt
@@ -0,0 +1,20 @@
These examples all do the same boring thing:
blink LEDs red, green, blue and white.

Each example represents a different a different LED protocol.


Special multi-port protocols:

ws2812bs an ws2812bi are used to connect 2 LED strips and displaying half of the pixels on one strip and the other half on the second strip. The ws2812bs mode splits the first half of the array to the first strip and the second half to the other strip. The ws2812bi interleaved mode sends every other pixel to the one strip then the other.

ws2812b8s is a mode that allows up to 8 ports (same letter port) to be displayed in parallel for faster LED strip refreshes. At 16MHz, this mode can support up to 6 ports before glitches appear.


The predefined LED strip types are:

* ws2812b
* apa104
* apa106
* sk6812 /sk6812b
* apa102

0 comments on commit 9a4d5df

Please sign in to comment.