Ws2812 code and terminal not working right.
jdolecki
Posts: 726
I making a small light for my robot using the ws2812 leds. I modified the code to change lights and patterns which is selected by the ( int h)
The problem is when I try to run terminal code to change (int H)h the led pattern changes but the light wont flash?
Also is there a simpler way to code this?
The problem is when I try to run terminal code to change (int H)h the led pattern changes but the light wont flash?
Also is there a simpler way to code this?
/* ws2812 Simple Test.c */ #include "simpletools.h" // Library includes #include "ws2812.h" #define LED_PIN 7 // led chain pin and count #define LED_COUNT 4 ws2812 *leds; // Set up ws2812 instance int a1[] = { COLOR_RED, COLOR_RED, // light pattern a persuit COLOR_BLUE, COLOR_BLUE }; int a2[] = { COLOR_BLUE, COLOR_BLUE, COLOR_RED, COLOR_RED }; int b1[] = { COLOR_YELLOW, COLOR_YELLOW, //light pattern b caution COLOR_YELLOW, COLOR_YELLOW}; int b2[] = { COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK }; int c1[] = { COLOR_RED, COLOR_RED, //light patter c stop COLOR_RED, COLOR_RED}; int c2[] = { COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK }; int d1[] = { COLOR_WHITE, COLOR_WHITE, //light patter d inspect COLOR_WHITE, COLOR_WHITE}; int d2[] = { COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE }; void main() { leds = ws2812b_open(); // Open leds instance int time; //blink time delay int color1; //pattern1 int color2; //pattern2 int i = 0; int h; while(1) { if (h == 0) { color1 = (a1); color2 = (a2); time = (250); } else if (h == 1) { color1 = (b1); color2 = (b2); time = (750); } else if (h == 2) { color1 = (c1); color2 = (c2); time = (500); } else { color1 = (d1); color2 = (d2); time = (750); } { i = (i + 1) % 2; //blink count if(i == 0) // if i is 0 { ws2812_set(leds, LED_PIN, // Display pattern A color1, LED_COUNT); } else // Otherwise... { ws2812_set(leds, LED_PIN, // Display pattern B color2, LED_COUNT); } pause(time); // blink time delay } } }
Comments