From 3094f1bd450e3a0e333df0dffa0f8df067058565 Mon Sep 17 00:00:00 2001 From: Joey Babcock Date: Wed, 28 Dec 2016 22:45:47 -0800 Subject: [PATCH 1/6] Added FPS output Also shows if its connected successfully --- arduino/ws2812_controller/ws2812_controller.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index 1632d1b..454faa4 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -48,7 +48,9 @@ void setup() { } uint8_t N = 0; - +int fpsCounter = 0; +int secondTimer = 0; +int redLedTimer = 0; void loop() { // Read data over socket int packetSize = port.parsePacket(); @@ -64,6 +66,16 @@ void loop() { pixels[N].B = (uint8_t)packetBuffer[i+3]; } ledstrip.show(pixels); + Serial.print("*"); + fpsCounter++; digitalWrite(0, 0); } + + if(millis() - secondTimer >= 1000) + { + secondTimer = millis(); + + Serial.printf("FPS: %d\n", fpsCounter); + fpsCounter = 0; + } } From 891bf470fe644bd9610cbe77628fb4f5bb7b2146 Mon Sep 17 00:00:00 2001 From: Joey Babcock Date: Thu, 29 Dec 2016 16:40:51 -0800 Subject: [PATCH 2/6] added macro for fps enabling --- arduino/ws2812_controller/ws2812_controller.ino | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index 454faa4..c49bd66 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -8,6 +8,7 @@ // Set this to the number of LEDs in your LED strip #define NUM_LEDS 260 #define BUFFER_LEN 1024 +#define PRINT_FPS 1 // Wifi and socket settings const char* ssid = "YOUR_WIFI_SSID"; @@ -44,13 +45,13 @@ void setup() { Serial.println(WiFi.localIP()); port.begin(localPort); ledstrip.init(NUM_LEDS); - pinMode(0, OUTPUT); } uint8_t N = 0; +#ifdef PRINT_FPS int fpsCounter = 0; int secondTimer = 0; -int redLedTimer = 0; +#endif void loop() { // Read data over socket int packetSize = port.parsePacket(); @@ -67,10 +68,11 @@ void loop() { } ledstrip.show(pixels); Serial.print("*"); - fpsCounter++; - digitalWrite(0, 0); + #ifdef PRINT_FPS + fpsCounter++; + #endif } - + #ifdef PRINT_FPS if(millis() - secondTimer >= 1000) { secondTimer = millis(); @@ -78,4 +80,5 @@ void loop() { Serial.printf("FPS: %d\n", fpsCounter); fpsCounter = 0; } + #endif } From 35d1ab23de9c7dffbad58b851cfb890354240212 Mon Sep 17 00:00:00 2001 From: Joey Babcock Date: Thu, 29 Dec 2016 16:43:23 -0800 Subject: [PATCH 3/6] left one digitalwrite in there... --- arduino/ws2812_controller/ws2812_controller.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index c49bd66..5ba1603 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -57,7 +57,6 @@ void loop() { int packetSize = port.parsePacket(); // If packets have been received, interpret the command if (packetSize) { - digitalWrite(0, 1); int len = port.read(packetBuffer, BUFFER_LEN); for(int i = 0; i < len; i+=4){ packetBuffer[len] = 0; From 443d8961ae632271717d9e0e0147351da66d2bb1 Mon Sep 17 00:00:00 2001 From: Joey Babcock Date: Fri, 30 Dec 2016 14:23:54 -0800 Subject: [PATCH 4/6] make "if" statement instead of just ifdef --- .../ws2812_controller/ws2812_controller.ino | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index 5ba1603..e209da2 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -48,10 +48,11 @@ void setup() { } uint8_t N = 0; -#ifdef PRINT_FPS -int fpsCounter = 0; -int secondTimer = 0; -#endif +if(PRINT_FPS == 1) +{ + int fpsCounter = 0; + int secondTimer = 0; +} void loop() { // Read data over socket int packetSize = port.parsePacket(); @@ -66,12 +67,14 @@ void loop() { pixels[N].B = (uint8_t)packetBuffer[i+3]; } ledstrip.show(pixels); - Serial.print("*"); - #ifdef PRINT_FPS + + if(PRINT_FPS == 1) + { + Serial.print("*"); fpsCounter++; - #endif + } } - #ifdef PRINT_FPS + if(PRINT_FPS == 1){ if(millis() - secondTimer >= 1000) { secondTimer = millis(); @@ -79,5 +82,5 @@ void loop() { Serial.printf("FPS: %d\n", fpsCounter); fpsCounter = 0; } - #endif + } } From 86706d7f94b67f9f56eaf66a1ce0a418f148aa67 Mon Sep 17 00:00:00 2001 From: Joey Babcock Date: Fri, 30 Dec 2016 14:28:32 -0800 Subject: [PATCH 5/6] apparently i don't actually know how if statements work... --- arduino/ws2812_controller/ws2812_controller.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index e209da2..ea5d41a 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -6,7 +6,7 @@ #include // Set this to the number of LEDs in your LED strip -#define NUM_LEDS 260 +#define NUM_LEDS 50 #define BUFFER_LEN 1024 #define PRINT_FPS 1 @@ -48,11 +48,11 @@ void setup() { } uint8_t N = 0; -if(PRINT_FPS == 1) -{ +#ifdef PRINT_FPS int fpsCounter = 0; int secondTimer = 0; -} +#endif + void loop() { // Read data over socket int packetSize = port.parsePacket(); From e95cef5a99365b4fc8d94d51ec1f6e8ca8ceddca Mon Sep 17 00:00:00 2001 From: Scott Lawson Date: Thu, 5 Jan 2017 00:02:43 -0800 Subject: [PATCH 6/6] Replaced "if" with "#if", changed int to uint32_t Replaced if statements with #if preprocessor macros. Replaced one #ifdef macro with #if. Changed `int secondTimer` to `uint32_t secondTimer` to avoid signed/unsigned integer comparison. The `millis()` function returns `uint32_t`. Removed asterix output from FPS output. --- .../ws2812_controller/ws2812_controller.ino | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/arduino/ws2812_controller/ws2812_controller.ino b/arduino/ws2812_controller/ws2812_controller.ino index 615dd33..e5054e3 100644 --- a/arduino/ws2812_controller/ws2812_controller.ino +++ b/arduino/ws2812_controller/ws2812_controller.ino @@ -5,11 +5,11 @@ #include #include "ws2812_i2s.h" -// Set this to the number of LEDs in your LED strip - +// Set to the number of LEDs in your LED strip #define NUM_LEDS 60 // Maximum number of packets to hold in the buffer. Don't change this. #define BUFFER_LEN 1024 +// Toggles FPS output (1 = print FPS over serial, 0 = disable output) #define PRINT_FPS 1 // Wifi and socket settings @@ -50,9 +50,9 @@ void setup() { } uint8_t N = 0; -#ifdef PRINT_FPS - int fpsCounter = 0; - int secondTimer = 0; +#if PRINT_FPS + uint16_t fpsCounter = 0; + uint32_t secondTimer = 0; #endif void loop() { @@ -60,29 +60,24 @@ void loop() { int packetSize = port.parsePacket(); // If packets have been received, interpret the command if (packetSize) { - int len = port.read(packetBuffer, BUFFER_LEN); - for(int i = 0; i < len; i+=4){ + int len = port.read(packetBuffer, BUFFER_LEN); + for(int i = 0; i < len; i+=4) { packetBuffer[len] = 0; N = packetBuffer[i]; pixels[N].R = (uint8_t)packetBuffer[i+1]; pixels[N].G = (uint8_t)packetBuffer[i+2]; pixels[N].B = (uint8_t)packetBuffer[i+3]; } - ledstrip.show(pixels); - - if(PRINT_FPS == 1) - { - Serial.print("*"); - fpsCounter++; - } - } - if(PRINT_FPS == 1){ - if(millis() - secondTimer >= 1000) - { - secondTimer = millis(); - - Serial.printf("FPS: %d\n", fpsCounter); - fpsCounter = 0; - } - } + ledstrip.show(pixels); + #if PRINT_FPS + fpsCounter++; + #endif + } + #if PRINT_FPS + if (millis() - secondTimer >= 1000U) { + secondTimer = millis(); + Serial.printf("FPS: %d\n", fpsCounter); + fpsCounter = 0; + } + #endif }