2016-10-12 23:50:00 +02:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
2017-12-18 21:46:29 +01:00
|
|
|
//#include <WebSocketsServer.h>
|
|
|
|
//#include <Hash.h>
|
2016-10-12 23:50:00 +02:00
|
|
|
#include <WiFiUdp.h>
|
2017-12-18 21:46:29 +01:00
|
|
|
#include <NeoPixelBus.h>
|
2016-10-12 23:50:00 +02:00
|
|
|
|
2017-01-05 09:02:43 +01:00
|
|
|
// Set to the number of LEDs in your LED strip
|
2017-12-18 21:46:29 +01:00
|
|
|
#define NUM_LEDS 242
|
2016-12-31 06:31:27 +01:00
|
|
|
// Maximum number of packets to hold in the buffer. Don't change this.
|
2017-12-18 21:46:29 +01:00
|
|
|
#define BUFFER_LEN 726
|
2017-01-05 09:02:43 +01:00
|
|
|
// Toggles FPS output (1 = print FPS over serial, 0 = disable output)
|
2016-12-30 01:40:51 +01:00
|
|
|
#define PRINT_FPS 1
|
2016-10-12 23:50:00 +02:00
|
|
|
|
2017-12-18 21:46:29 +01:00
|
|
|
//NeoPixelBus settings
|
|
|
|
const uint8_t PixelPin = 3; // make sure to set this to the correct pin, ignored for Esp8266(set to 3 by default for DMA)
|
|
|
|
|
2016-10-12 23:50:00 +02:00
|
|
|
// Wifi and socket settings
|
2017-12-18 21:46:29 +01:00
|
|
|
const char* ssid = "ASUS_VIVOBOOK";
|
|
|
|
const char* password = "T!PT)Psecret";
|
|
|
|
unsigned int localPort = 7778;
|
|
|
|
byte packetBuffer[BUFFER_LEN];
|
|
|
|
RgbColor ledDataBuffer[NUM_LEDS];
|
2016-10-12 23:50:00 +02:00
|
|
|
|
|
|
|
// LED strip
|
2017-12-18 21:46:29 +01:00
|
|
|
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> ledstrip(NUM_LEDS, PixelPin);
|
|
|
|
|
2016-10-12 23:50:00 +02:00
|
|
|
WiFiUDP port;
|
|
|
|
|
2016-10-23 06:55:22 +02:00
|
|
|
// Network information
|
2016-12-28 05:09:06 +01:00
|
|
|
// IP must match the IP in config.py
|
2017-12-18 21:46:29 +01:00
|
|
|
IPAddress ip(192, 168, 137, 200);
|
2016-12-28 05:09:06 +01:00
|
|
|
// Set gateway to your router's gateway
|
2017-12-18 21:46:29 +01:00
|
|
|
IPAddress gateway(192, 168, 137, 1);
|
2016-10-23 06:55:22 +02:00
|
|
|
IPAddress subnet(255, 255, 255, 0);
|
|
|
|
|
2016-10-12 23:50:00 +02:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
2017-12-18 21:46:29 +01:00
|
|
|
//WiFi.config(ip, gateway, subnet);
|
|
|
|
WiFi.mode(WIFI_STA);
|
2016-10-12 23:50:00 +02:00
|
|
|
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);
|
2017-12-18 21:46:29 +01:00
|
|
|
ledstrip.Begin();//Begin output
|
|
|
|
ledstrip.Show();//Clear the strip for use
|
2016-10-12 23:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t N = 0;
|
2017-01-05 09:02:43 +01:00
|
|
|
#if PRINT_FPS
|
|
|
|
uint16_t fpsCounter = 0;
|
|
|
|
uint32_t secondTimer = 0;
|
2016-12-30 23:28:32 +01:00
|
|
|
#endif
|
|
|
|
|
2016-10-12 23:50:00 +02:00
|
|
|
void loop() {
|
|
|
|
// Read data over socket
|
|
|
|
int packetSize = port.parsePacket();
|
|
|
|
// If packets have been received, interpret the command
|
|
|
|
if (packetSize) {
|
2017-01-05 09:02:43 +01:00
|
|
|
int len = port.read(packetBuffer, BUFFER_LEN);
|
|
|
|
for(int i = 0; i < len; i+=4) {
|
2016-10-12 23:50:00 +02:00
|
|
|
packetBuffer[len] = 0;
|
|
|
|
N = packetBuffer[i];
|
2017-12-18 21:46:29 +01:00
|
|
|
RgbColor pixel((uint8_t)packetBuffer[i+1], (uint8_t)packetBuffer[i+2], (uint8_t)packetBuffer[i+3]);
|
|
|
|
ledstrip.SetPixelColor(N, pixel);
|
|
|
|
}
|
|
|
|
ledstrip.Show();
|
|
|
|
Serial.print("/");
|
2017-01-05 09:02:43 +01:00
|
|
|
}
|
2017-12-18 21:46:29 +01:00
|
|
|
}
|