Update ws2812_controller.ino
This commit is contained in:
parent
61f4defaee
commit
24289b61ca
@ -1,79 +1,79 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
//#include <WebSocketsServer.h>
|
//#include <WebSocketsServer.h>
|
||||||
//#include <Hash.h>
|
//#include <Hash.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
|
|
||||||
// Set to the number of LEDs in your LED strip
|
// Set to the number of LEDs in your LED strip
|
||||||
#define NUM_LEDS 242
|
#define NUM_LEDS 242
|
||||||
// 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 726
|
#define BUFFER_LEN 726
|
||||||
// Toggles FPS output (1 = print FPS over serial, 0 = disable output)
|
// Toggles FPS output (1 = print FPS over serial, 0 = disable output)
|
||||||
#define PRINT_FPS 1
|
#define PRINT_FPS 1
|
||||||
|
|
||||||
//NeoPixelBus settings
|
//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)
|
const uint8_t PixelPin = 3; // make sure to set this to the correct pin, ignored for Esp8266(set to 3 by default for DMA)
|
||||||
|
|
||||||
// Wifi and socket settings
|
// Wifi and socket settings
|
||||||
const char* ssid = "ASUS_VIVOBOOK";
|
const char* ssid = "YOUR_WIFI_SSID";
|
||||||
const char* password = "T!PT)Psecret";
|
const char* password = "YOUR_WIFI_PASSWORD";
|
||||||
unsigned int localPort = 7778;
|
unsigned int localPort = 7778;
|
||||||
byte packetBuffer[BUFFER_LEN];
|
byte packetBuffer[BUFFER_LEN];
|
||||||
RgbColor ledDataBuffer[NUM_LEDS];
|
RgbColor ledDataBuffer[NUM_LEDS];
|
||||||
|
|
||||||
// LED strip
|
// LED strip
|
||||||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> ledstrip(NUM_LEDS, PixelPin);
|
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> ledstrip(NUM_LEDS, PixelPin);
|
||||||
|
|
||||||
WiFiUDP port;
|
WiFiUDP port;
|
||||||
|
|
||||||
// Network information
|
// Network information
|
||||||
// IP must match the IP in config.py
|
// IP must match the IP in config.py
|
||||||
IPAddress ip(192, 168, 137, 200);
|
IPAddress ip(192, 168, 137, 200);
|
||||||
// Set gateway to your router's gateway
|
// Set gateway to your router's gateway
|
||||||
IPAddress gateway(192, 168, 137, 1);
|
IPAddress gateway(192, 168, 137, 1);
|
||||||
IPAddress subnet(255, 255, 255, 0);
|
IPAddress subnet(255, 255, 255, 0);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
//WiFi.config(ip, gateway, subnet);
|
//WiFi.config(ip, gateway, subnet);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
// Connect to wifi and print the IP address over serial
|
// Connect to wifi and print the IP address over serial
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.print("Connected to ");
|
Serial.print("Connected to ");
|
||||||
Serial.println(ssid);
|
Serial.println(ssid);
|
||||||
Serial.print("IP address: ");
|
Serial.print("IP address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
port.begin(localPort);
|
port.begin(localPort);
|
||||||
ledstrip.Begin();//Begin output
|
ledstrip.Begin();//Begin output
|
||||||
ledstrip.Show();//Clear the strip for use
|
ledstrip.Show();//Clear the strip for use
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t N = 0;
|
uint8_t N = 0;
|
||||||
#if PRINT_FPS
|
#if PRINT_FPS
|
||||||
uint16_t fpsCounter = 0;
|
uint16_t fpsCounter = 0;
|
||||||
uint32_t secondTimer = 0;
|
uint32_t secondTimer = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Read data over socket
|
// Read data over socket
|
||||||
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];
|
||||||
RgbColor pixel((uint8_t)packetBuffer[i+1], (uint8_t)packetBuffer[i+2], (uint8_t)packetBuffer[i+3]);
|
RgbColor pixel((uint8_t)packetBuffer[i+1], (uint8_t)packetBuffer[i+2], (uint8_t)packetBuffer[i+3]);
|
||||||
ledstrip.SetPixelColor(N, pixel);
|
ledstrip.SetPixelColor(N, pixel);
|
||||||
}
|
}
|
||||||
ledstrip.Show();
|
ledstrip.Show();
|
||||||
Serial.print("/");
|
Serial.print("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user