PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
WS2812_Demo.cpp

Continuously cycle an RGB LED between bright and dim white

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
project(WS2812_Demo)
create_simple_executable(${PROJECT_NAME} WS2812_Demo.cpp)
static const Pin::Mask LED_TX_PIN_MASK = Pin::Mask::P0;
static const WS2812::Type LED_TYPE = WS2812::Type::GRB;
static const unsigned int MAX_BRIGHTNESS = 0x0C0C0C;
int main() {
const WS2812 led(LED_TX_PIN_MASK, LED_TYPE);
const int delay = 40 * MILLISECOND;
while (1) {
unsigned int i;
// Go bright
for (i = 0; i < MAX_BRIGHTNESS; i += 0x010101) {
led.send(i);
waitcnt(delay + CNT);
}
// Go dim
for (; i; i -= 0x010101) {
led.send(i);
waitcnt(delay + CNT);
}
}
}
PropWare::WS2812
An easy-to-use, cheap, small, and bright multicolor LED capable of being strung together in a lengthy...
Definition: ws2812.h:36
led
void led(int n, int state)
Set a blue LED (from 0 to 5) to a state (ON or OFF). Examples: led(1, ON) turns the blue LED next to ...
Definition: leds_led.c:9
PropWare::Pin
Utility class to handle general purpose I/O pins.
Definition: pin.h:36
main
int main(void)
Definition: GraphicsTest.c:20
ws2812.h
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33