Merge remote-tracking branch 'refs/remotes/origin/master' into raspberry-pi-support

This commit is contained in:
Scott Lawson 2017-01-05 02:10:34 -08:00
commit d828f5a273

View File

@ -5,10 +5,12 @@
#include <WiFiUdp.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
// 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
const char* ssid = "YOUR_WIFI_SSID";
@ -45,17 +47,19 @@ void setup() {
Serial.println(WiFi.localIP());
port.begin(localPort);
ledstrip.init(NUM_LEDS);
pinMode(0, OUTPUT);
}
uint8_t N = 0;
#if PRINT_FPS
uint16_t fpsCounter = 0;
uint32_t secondTimer = 0;
#endif
void loop() {
// Read data over socket
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;
@ -65,6 +69,15 @@ void loop() {
pixels[N].B = (uint8_t)packetBuffer[i+3];
}
ledstrip.show(pixels);
digitalWrite(0, 0);
#if PRINT_FPS
fpsCounter++;
#endif
}
#if PRINT_FPS
if (millis() - secondTimer >= 1000U) {
secondTimer = millis();
Serial.printf("FPS: %d\n", fpsCounter);
fpsCounter = 0;
}
#endif
}