PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Light
ws2812 Simple Test.c
1
/*
2
ws2812 Simple Test.c
3
*/
4
5
#include "
simpletools.h
"
// Library includes
6
#include "ws2812.h"
7
8
#define LED_PIN 13 // led chain pin and count
9
#define LED_COUNT 4
10
11
ws2812
*
leds
;
// Set up ws2812 instance
12
13
int
lightsA[] = { COLOR_RED, COLOR_YELLOW,
// 4-light pattern A
14
COLOR_GREEN, COLOR_BLUE };
15
int
lightsB[] = { COLOR_YELLOW, COLOR_RED,
// 4-light pattern B
16
COLOR_BLUE, COLOR_GREEN };
17
void
main
()
// Main function
18
{
19
leds
=
ws2812b_open
();
// Open leds instance
20
21
int
i = 0;
// Counting variable
22
23
while
(1)
// Main loop
24
{
25
i = (i + 1) % 2;
// i counts 0, 1, 0, 1,...
26
27
print
(
"i = %d\n"
, i);
28
if
(i == 0)
// if i is 0
29
{
30
ws2812_set
(
leds
, LED_PIN,
// Display pattern A
31
lightsA, LED_COUNT);
32
}
33
else
// Otherwise...
34
{
35
ws2812_set
(
leds
, LED_PIN,
// Display pattern B
36
lightsB, LED_COUNT);
37
}
38
pause
(100);
// 0.1 s before repeat
39
}
40
}
41
ws2812_t
Definition:
ws2812.h:53
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
ws2812_set
void ws2812_set(ws2812_t *driver, int pin, uint32_t *colors, int count)
Set color pattern on a chain of LEDs.
Definition:
ws2812.c:56
leds
void leds(int bits)
Sets the on/off states of the 6 blue LEDs with a number that contains six binary 1/0 digits....
ws2812b_open
ws2812_t * ws2812b_open(void)
Open a driver for WS2812B chips.
Definition:
ws2812b_open.c:17
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17