It's working now.
Fixes include: * It's working now. ;-) * Added new commands: * ? returns a help via Serial * r sets every LED to a random color * t sets the whole strip to green * Afte receiving the first command, the status LED changes for every received command.
This commit is contained in:
parent
b47a0ab935
commit
030a37daf6
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
@ -5,8 +5,12 @@ void cmd_output();
|
|||||||
void cmd_clear();
|
void cmd_clear();
|
||||||
void cmd_version();
|
void cmd_version();
|
||||||
void cmd_get_max();
|
void cmd_get_max();
|
||||||
|
void cmd_random_color();
|
||||||
|
void cmd_test();
|
||||||
|
void cmd_help();
|
||||||
void send_nack();
|
void send_nack();
|
||||||
void send_ack();
|
void send_ack();
|
||||||
|
void send(byte data);
|
||||||
void status_led_on();
|
void status_led_on();
|
||||||
void status_led_off();
|
void status_led_off();
|
||||||
void status_led_toggle();
|
void status_led_toggle();
|
||||||
|
80
src/main.cpp
80
src/main.cpp
@ -4,7 +4,7 @@
|
|||||||
#define WS2812B_PIN 14
|
#define WS2812B_PIN 14
|
||||||
#define LED_DATA_PIN 13 // D7 // Hardware-MOSI
|
#define LED_DATA_PIN 13 // D7 // Hardware-MOSI
|
||||||
#define LED_CLOCK_PIN 14 // D5 // Hardware-CLK
|
#define LED_CLOCK_PIN 14 // D5 // Hardware-CLK
|
||||||
#define STATUS_LED_PIN 1
|
#define STATUS_LED_PIN 16
|
||||||
#define FIRMWARE_VERSION_MAJOR 1
|
#define FIRMWARE_VERSION_MAJOR 1
|
||||||
#define FIRMWARE_VERSION_MINOR 3
|
#define FIRMWARE_VERSION_MINOR 3
|
||||||
#define MAX_LED_COUNT 10000
|
#define MAX_LED_COUNT 10000
|
||||||
@ -17,11 +17,13 @@ unsigned long blink_mode_timeout_timer_ts;
|
|||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(9600);
|
||||||
|
Serial.setTimeout(1);
|
||||||
|
//Serial.println("Online!");
|
||||||
led_count = 256;
|
led_count = 256;
|
||||||
leds = new CRGB[256];
|
leds = new CRGB[256];
|
||||||
//FastLED.addLeds<WS2812B, WS2812B_PIN, GRB>(leds, 256);
|
//FastLED.addLeds<WS2812B, WS2812B_PIN, GRB>(leds, 256);
|
||||||
FastLED.addLeds<APA102, LED_DATA_PIN, LED_CLOCK_PIN>(leds, 256);
|
FastLED.addLeds<APA102, LED_DATA_PIN, LED_CLOCK_PIN, GRB, DATA_RATE_MHZ(1)>(leds, 256);
|
||||||
FastLED[0].setLeds(leds, 256);
|
FastLED[0].setLeds(leds, 256);
|
||||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||||
set_blink(0);
|
set_blink(0);
|
||||||
@ -29,9 +31,11 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (Serial.available()) {
|
Serial.setTimeout(1);
|
||||||
byte recv = Serial.read();
|
byte buffer=0;
|
||||||
switch(recv) {
|
size_t received = Serial.readBytes(&buffer, 1);
|
||||||
|
if (received==1) {
|
||||||
|
switch(buffer) {
|
||||||
case 'L': cmd_length(); break;
|
case 'L': cmd_length(); break;
|
||||||
case 'F': cmd_fill(); break;
|
case 'F': cmd_fill(); break;
|
||||||
case 'R': cmd_receive(); break;
|
case 'R': cmd_receive(); break;
|
||||||
@ -39,6 +43,9 @@ void loop() {
|
|||||||
case 'C': cmd_clear(); break;
|
case 'C': cmd_clear(); break;
|
||||||
case 'V': cmd_version(); break;
|
case 'V': cmd_version(); break;
|
||||||
case 'M': cmd_get_max(); break;
|
case 'M': cmd_get_max(); break;
|
||||||
|
case 'r': cmd_random_color(); break;
|
||||||
|
case 't': cmd_test(); break;
|
||||||
|
case '?': cmd_help(); break;
|
||||||
default: send_nack(); break;
|
default: send_nack(); break;
|
||||||
}
|
}
|
||||||
set_blink(1);
|
set_blink(1);
|
||||||
@ -68,7 +75,7 @@ void blink() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // active after receiving a command - ends after 500ms
|
case 1: // active after receiving a command - ends after 500ms
|
||||||
if(blink_timer > 30) {
|
/*if(blink_timer > 30) {
|
||||||
blink_timer_ts = now;
|
blink_timer_ts = now;
|
||||||
status_led_toggle();
|
status_led_toggle();
|
||||||
}
|
}
|
||||||
@ -88,7 +95,11 @@ void blink() {
|
|||||||
} else {
|
} else {
|
||||||
blink_timer_ts = now;
|
blink_timer_ts = now;
|
||||||
status_led_off();
|
status_led_off();
|
||||||
}
|
}*/
|
||||||
|
status_led_toggle();
|
||||||
|
set_blink(2);
|
||||||
|
break;
|
||||||
|
case 2: // do nothing
|
||||||
break;
|
break;
|
||||||
default: // should newer be reached
|
default: // should newer be reached
|
||||||
if (blink_timer > 1000) {
|
if (blink_timer > 1000) {
|
||||||
@ -123,7 +134,7 @@ void cmd_fill() {
|
|||||||
void cmd_receive() {
|
void cmd_receive() {
|
||||||
uint16_t first_led = receive_word();
|
uint16_t first_led = receive_word();
|
||||||
uint16_t cmd_leds = receive_word();
|
uint16_t cmd_leds = receive_word();
|
||||||
if (first_led <= led_count && cmd_leds>0 && first_led + cmd_leds + 1 <= led_count) {
|
if (first_led <= led_count && cmd_leds>0 && first_led + cmd_leds <= led_count) {
|
||||||
uint16_t end_led = first_led + cmd_leds;
|
uint16_t end_led = first_led + cmd_leds;
|
||||||
for(uint16_t i=first_led; i<end_led; i++) {
|
for(uint16_t i=first_led; i<end_led; i++) {
|
||||||
leds[i] = receive_color();
|
leds[i] = receive_color();
|
||||||
@ -156,26 +167,67 @@ void cmd_clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmd_version() {
|
void cmd_version() {
|
||||||
Serial.write(FIRMWARE_VERSION_MAJOR);
|
send(FIRMWARE_VERSION_MAJOR);
|
||||||
Serial.write(FIRMWARE_VERSION_MINOR);
|
send(FIRMWARE_VERSION_MINOR);
|
||||||
send_ack();
|
send_ack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_get_max() {
|
void cmd_get_max() {
|
||||||
Serial.write(MAX_LED_COUNT >> 8);
|
Serial.write(MAX_LED_COUNT >> 8);
|
||||||
Serial.write(MAX_LED_COUNT & 0xFF);
|
send((byte)(MAX_LED_COUNT & 0xFF));
|
||||||
|
send_ack();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_random_color() {
|
||||||
|
for (int i=0; i<led_count; i++) {
|
||||||
|
leds[i] = CRGB(random8(), random8(), random8());
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
send_ack();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_test() {
|
||||||
|
for (int i=0; i<led_count; i++) {
|
||||||
|
leds[i] = CRGB::Red;
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
send_ack();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_help() {
|
||||||
|
Serial.println("L <length> Set new LED strip length.");
|
||||||
|
Serial.println("F <start> <count> <color> Fills the given part with color.");
|
||||||
|
Serial.println("R <start> <count> <color>[] Sets colors for the fiven area.");
|
||||||
|
Serial.println("O Shows the set colors on the strip.");
|
||||||
|
Serial.println("C Sets all LEDs to black.");
|
||||||
|
Serial.println("V Returns the firmware version as two bytes.");
|
||||||
|
Serial.println("M Returns the maximum number of LEDs.");
|
||||||
|
Serial.println("r Sets all LEDs to random colors.");
|
||||||
|
Serial.println("t Sets the whole strip to red.");
|
||||||
|
Serial.println("? Displays this help.");
|
||||||
send_ack();
|
send_ack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_ack() {
|
void send_ack() {
|
||||||
Serial.write('A');
|
send('A');
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_nack() {
|
void send_nack() {
|
||||||
Serial.write('N');
|
send('N');
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(byte data) {
|
||||||
|
Serial.write(data);
|
||||||
|
//Serial.write(0x00);
|
||||||
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t receive_byte() {
|
uint8_t receive_byte() {
|
||||||
|
/*byte buffer;
|
||||||
|
Serial.setTimeout(5);
|
||||||
|
size_t count = Serial.readBytes(&buffer, 1);
|
||||||
|
if (count==1) return buffer;
|
||||||
|
else return 0;*/
|
||||||
while (!Serial.available()) {}
|
while (!Serial.available()) {}
|
||||||
return Serial.read();
|
return Serial.read();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user