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.
This commit is contained in:
parent
daf08d45bb
commit
e95cef5a99
@ -5,11 +5,11 @@
|
|||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include "ws2812_i2s.h"
|
#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
|
#define NUM_LEDS 60
|
||||||
// Maximum number of packets to hold in the buffer. Don't change this.
|
// Maximum number of packets to hold in the buffer. Don't change this.
|
||||||
#define BUFFER_LEN 1024
|
#define BUFFER_LEN 1024
|
||||||
|
// Toggles FPS output (1 = print FPS over serial, 0 = disable output)
|
||||||
#define PRINT_FPS 1
|
#define PRINT_FPS 1
|
||||||
|
|
||||||
// Wifi and socket settings
|
// Wifi and socket settings
|
||||||
@ -50,9 +50,9 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t N = 0;
|
uint8_t N = 0;
|
||||||
#ifdef PRINT_FPS
|
#if PRINT_FPS
|
||||||
int fpsCounter = 0;
|
uint16_t fpsCounter = 0;
|
||||||
int secondTimer = 0;
|
uint32_t secondTimer = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -60,29 +60,24 @@ void loop() {
|
|||||||
int packetSize = port.parsePacket();
|
int packetSize = port.parsePacket();
|
||||||
// If packets have been received, interpret the command
|
// If packets have been received, interpret the command
|
||||||
if (packetSize) {
|
if (packetSize) {
|
||||||
int len = port.read(packetBuffer, BUFFER_LEN);
|
int len = port.read(packetBuffer, BUFFER_LEN);
|
||||||
for(int i = 0; i < len; i+=4){
|
for(int i = 0; i < len; i+=4) {
|
||||||
packetBuffer[len] = 0;
|
packetBuffer[len] = 0;
|
||||||
N = packetBuffer[i];
|
N = packetBuffer[i];
|
||||||
pixels[N].R = (uint8_t)packetBuffer[i+1];
|
pixels[N].R = (uint8_t)packetBuffer[i+1];
|
||||||
pixels[N].G = (uint8_t)packetBuffer[i+2];
|
pixels[N].G = (uint8_t)packetBuffer[i+2];
|
||||||
pixels[N].B = (uint8_t)packetBuffer[i+3];
|
pixels[N].B = (uint8_t)packetBuffer[i+3];
|
||||||
}
|
}
|
||||||
ledstrip.show(pixels);
|
ledstrip.show(pixels);
|
||||||
|
#if PRINT_FPS
|
||||||
if(PRINT_FPS == 1)
|
fpsCounter++;
|
||||||
{
|
#endif
|
||||||
Serial.print("*");
|
}
|
||||||
fpsCounter++;
|
#if PRINT_FPS
|
||||||
}
|
if (millis() - secondTimer >= 1000U) {
|
||||||
}
|
secondTimer = millis();
|
||||||
if(PRINT_FPS == 1){
|
Serial.printf("FPS: %d\n", fpsCounter);
|
||||||
if(millis() - secondTimer >= 1000)
|
fpsCounter = 0;
|
||||||
{
|
}
|
||||||
secondTimer = millis();
|
#endif
|
||||||
|
|
||||||
Serial.printf("FPS: %d\n", fpsCounter);
|
|
||||||
fpsCounter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user