audio-reactive-led-strip/arduino/ws2812_controller/ws2812_controller.ino
Scott Lawson 17313c254b Major refactoring and update
* Moved all module settings to a new config.py file
* Completely overhauled visualize.py and added a new radiate effect that
colours the radiative beats according the beat frequency.
* Improved some constants like the decay constant to be parametric so
that they scale to any led strip size
* Added temporal dithering to Beat.update_pixels() so that it now
supports fractional speed values. Being limited to integral values was
starting to become a problem.
* Overhauled and simplified the LED module.
* When updating pixels, the LED module no longer sends UDP packets for
pixels that have not changed. This optimization reduces the packet load
significantly and should allow for higher refresh rates.
* Renamed lookup_table.npy to gamm_table.npy to better reflect that the
table is used for gamma correction of the LED strip
2016-10-13 22:27:45 -07:00

62 lines
1.5 KiB
C++

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WebSocketsServer.h>
#include <Hash.h>
#include <WiFiUdp.h>
#include <ws2812_i2s.h>
#define NUM_LEDS 240
#define BUFFER_LEN 1024
// Wifi and socket settings
const char* ssid = "LAWSON-LINK-2.4";
const char* password = "felixlina10";
unsigned int localPort = 7777;
char packetBuffer[BUFFER_LEN];
// LED strip
static WS2812 ledstrip;
static Pixel_t pixels[NUM_LEDS];
WiFiUDP port;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Connect to wifi and print the IP address over serial
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
port.begin(localPort);
ledstrip.init(NUM_LEDS);
}
uint8_t N = 0;
void loop() {
// Read data over socket
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){
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);
}
// Always update strip to improve temporal dithering performance
ledstrip.show(pixels);
}