Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rename!

  • Loading branch information...
commit b6045bdeacd99c5e741472d633532e6f6991885d 1 parent c91e268
Limor "Ladyada" Fried ladyada authored
30 WS2801.cpp → Adafruit_WS2801.cpp
View
@@ -6,21 +6,21 @@
/*****************************************************************************/
// Constructor for use with hardware SPI (specific clock/data pins):
-WS2801::WS2801(uint16_t n, uint8_t order) {
+Adafruit_WS2801::Adafruit_WS2801(uint16_t n, uint8_t order) {
rgb_order = order;
alloc(n);
updatePins();
}
// Constructor for use with arbitrary clock/data pins:
-WS2801::WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order) {
+Adafruit_WS2801::Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order) {
rgb_order = order;
alloc(n);
updatePins(dpin, cpin);
}
// Allocate 3 bytes per pixel, init to RGB 'off' state:
-void WS2801::alloc(uint16_t n) {
+void Adafruit_WS2801::alloc(uint16_t n) {
begun = false;
numLEDs = ((pixels = (uint8_t *)calloc(n, 3)) != NULL) ? n : 0;
}
@@ -31,7 +31,7 @@ void WS2801::alloc(uint16_t n) {
// command. If using this constructor, MUST follow up with updateLength()
// and updatePins() to establish the strand length and output pins!
// Also, updateOrder() to change RGB vs GRB order (RGB is default).
-WS2801::WS2801(void) {
+Adafruit_WS2801::Adafruit_WS2801(void) {
begun = false;
numLEDs = 0;
pixels = NULL;
@@ -40,7 +40,7 @@ WS2801::WS2801(void) {
}
// Activate hard/soft SPI as appropriate:
-void WS2801::begin(void) {
+void Adafruit_WS2801::begin(void) {
if(hardwareSPI == true) {
startSPI();
} else {
@@ -51,7 +51,7 @@ void WS2801::begin(void) {
}
// Change pin assignments post-constructor, switching to hardware SPI:
-void WS2801::updatePins(void) {
+void Adafruit_WS2801::updatePins(void) {
hardwareSPI = true;
datapin = clkpin = 0;
// If begin() was previously invoked, init the SPI hardware now:
@@ -63,7 +63,7 @@ void WS2801::updatePins(void) {
}
// Change pin assignments post-constructor, using arbitrary pins:
-void WS2801::updatePins(uint8_t dpin, uint8_t cpin) {
+void Adafruit_WS2801::updatePins(uint8_t dpin, uint8_t cpin) {
if(begun == true) { // If begin() was previously invoked...
// If previously using hardware SPI, turn that off:
@@ -86,7 +86,7 @@ void WS2801::updatePins(uint8_t dpin, uint8_t cpin) {
}
// Enable SPI hardware and set up protocol details:
-void WS2801::startSPI(void) {
+void Adafruit_WS2801::startSPI(void) {
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
@@ -99,12 +99,12 @@ void WS2801::startSPI(void) {
// SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz
}
-uint16_t WS2801::numPixels(void) {
+uint16_t Adafruit_WS2801::numPixels(void) {
return numLEDs;
}
// Change strand length (see notes with empty constructor, above):
-void WS2801::updateLength(uint16_t n) {
+void Adafruit_WS2801::updateLength(uint16_t n) {
if(pixels != NULL) free(pixels); // Free existing data (if any)
// Allocate new data -- note: ALL PIXELS ARE CLEARED
numLEDs = ((pixels = (uint8_t *)calloc(n, 3)) != NULL) ? n : 0;
@@ -112,13 +112,13 @@ void WS2801::updateLength(uint16_t n) {
}
// Change RGB data order (see notes with empty constructor, above):
-void WS2801::updateOrder(uint8_t order) {
+void Adafruit_WS2801::updateOrder(uint8_t order) {
rgb_order = order;
// Existing LED data, if any, is NOT reformatted to new data order.
// Calling function should clear or fill pixel data anew.
}
-void WS2801::show(void) {
+void Adafruit_WS2801::show(void) {
uint16_t i, nl3 = numLEDs * 3; // 3 bytes per LED
uint8_t bit;
@@ -143,7 +143,7 @@ void WS2801::show(void) {
}
// Set pixel color from separate 8-bit R, G, B components:
-void WS2801::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
+void Adafruit_WS2801::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
if(n < numLEDs) { // Arrays are 0-indexed, thus NOT '<='
uint8_t *p = &pixels[n * 3];
// See notes later regarding color order
@@ -159,7 +159,7 @@ void WS2801::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
}
// Set pixel color from 'packed' 32-bit RGB value:
-void WS2801::setPixelColor(uint16_t n, uint32_t c) {
+void Adafruit_WS2801::setPixelColor(uint16_t n, uint32_t c) {
if(n < numLEDs) { // Arrays are 0-indexed, thus NOT '<='
uint8_t *p = &pixels[n * 3];
// To keep the show() loop as simple & fast as possible, the
@@ -178,7 +178,7 @@ void WS2801::setPixelColor(uint16_t n, uint32_t c) {
}
// Query color from previously-set pixel (returns packed 32-bit RGB value)
-uint32_t WS2801::getPixelColor(uint16_t n) {
+uint32_t Adafruit_WS2801::getPixelColor(uint16_t n) {
if(n < numLEDs) {
uint16_t ofs = n * 3;
// To keep the show() loop as simple & fast as possible, the
8 WS2801.h → Adafruit_WS2801.h
View
@@ -13,16 +13,16 @@
#define WS2801_RGB 0
#define WS2801_GRB 1
-class WS2801 {
+class Adafruit_WS2801 {
public:
// Configurable pins:
- WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
+ Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
// Use SPI hardware; specific pins only:
- WS2801(uint16_t n, uint8_t order=WS2801_RGB);
+ Adafruit_WS2801(uint16_t n, uint8_t order=WS2801_RGB);
// Empty constructor; init pins/strand length/data order later:
- WS2801();
+ Adafruit_WS2801();
void
begin(void),
21 README.txt
View
@@ -1,6 +1,23 @@
-This is an Arduino library for WS2801 LED pixels
+Example library for driving Adafruit WS2801 pixels!
-Pick some up at http://www.adafruit.com/products/322
+
+ Designed specifically to work with the Adafruit RGB Pixels!
+ 12mm Bullet shape ----> https://www.adafruit.com/products/322
+ 12mm Flat shape ----> https://www.adafruit.com/products/738
+ 36mm Square shape ----> https://www.adafruit.com/products/683
+
+ These pixels use SPI to transmit the color data, and have built in
+ high speed PWM drivers for 24 bit color per pixel
+ 2 pins are required to interface
+
+ Adafruit invests time and resources providing this open source code,
+ please support Adafruit and open-source hardware by purchasing
+ products from Adafruit!
+
+ Written by Limor Fried/Ladyada for Adafruit Industries.
+ BSD license, all text above must be included in any redistribution
+
+-------------------------------------
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder WS2801. Check that the WS2801 folder contains WS2801.cpp and WS2801.h
35 examples/strandtest/strandtest.pde
View
@@ -1,25 +1,44 @@
#include "SPI.h"
-#include "WS2801.h"
+#include "Adafruit_WS2801.h"
/*****************************************************************************
-Example sketch for driving WS2801 pixels
+Example sketch for driving Adafruit WS2801 pixels!
+
+
+ Designed specifically to work with the Adafruit RGB Pixels!
+ 12mm Bullet shape ----> https://www.adafruit.com/products/322
+ 12mm Flat shape ----> https://www.adafruit.com/products/738
+ 36mm Square shape ----> https://www.adafruit.com/products/683
+
+ These pixels use SPI to transmit the color data, and have built in
+ high speed PWM drivers for 24 bit color per pixel
+ 2 pins are required to interface
+
+ Adafruit invests time and resources providing this open source code,
+ please support Adafruit and open-source hardware by purchasing
+ products from Adafruit!
+
+ Written by Limor Fried/Ladyada for Adafruit Industries.
+ BSD license, all text above must be included in any redistribution
+
*****************************************************************************/
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
// The colors of the wires may be totally different so
// BE SURE TO CHECK YOUR PIXELS TO SEE WHICH WIRES TO USE!
-int dataPin = 2;
-int clockPin = 3;
+int dataPin = 2; // Yellow wire on Adafruit Pixels
+int clockPin = 3; // Green wire on Adafruit Pixels
+
// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply
// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
-WS2801 strip = WS2801(25, dataPin, clockPin);
+Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);
// Optional: leave off pin numbers to use hardware SPI
// (pinout is then specific to each board and can't be changed)
-//WS2801 strip = WS2801(25);
+//Adafruit_WS2801 strip = Adafruit_WS2801(25);
// For 36mm LED pixels: these pixels internally represent color in a
// different format. Either of the above constructors can accept an
@@ -27,8 +46,8 @@ WS2801 strip = WS2801(25, dataPin, clockPin);
// WS2801_GRB is the GRB order required by the 36mm pixels. Other
// than this parameter, your code does not need to do anything different;
// the library will handle the format change. Examples:
-//WS2801 strip = WS2801(25, dataPin, clockPin, WS2801_GRB);
-//WS2801 strip = WS2801(25, WS2801_GRB);
+//Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin, WS2801_GRB);
+//Adafruit_WS2801 strip = Adafruit_WS2801(25, WS2801_GRB);
void setup() {
Please sign in to comment.
Something went wrong with that request. Please try again.