Add files via upload

Uses NeoPixelBus, now uploaded in the right place too.
This commit is contained in:
not-matt 2017-12-18 20:46:29 +00:00 committed by GitHub
parent 2be945c179
commit 51a679ed10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,38 +1,43 @@
#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 "ws2812_i2s.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 60 #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 1024 #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
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 = "YOUR_WIFI_SSID"; const char* ssid = "ASUS_VIVOBOOK";
const char* password = "YOUR_WIFI_PASSWORD"; const char* password = "T!PT)Psecret";
unsigned int localPort = 7777; unsigned int localPort = 7778;
char packetBuffer[BUFFER_LEN]; byte packetBuffer[BUFFER_LEN];
RgbColor ledDataBuffer[NUM_LEDS];
// LED strip // LED strip
static WS2812 ledstrip; NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> ledstrip(NUM_LEDS, PixelPin);
static Pixel_t pixels[NUM_LEDS];
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, 0, 150); IPAddress ip(192, 168, 137, 200);
// Set gateway to your router's gateway // Set gateway to your router's gateway
IPAddress gateway(192, 168, 0, 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.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
@ -46,7 +51,8 @@ void setup() {
Serial.print("IP address: "); Serial.print("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
port.begin(localPort); port.begin(localPort);
ledstrip.init(NUM_LEDS); ledstrip.Begin();//Begin output
ledstrip.Show();//Clear the strip for use
} }
uint8_t N = 0; uint8_t N = 0;
@ -64,20 +70,10 @@ void loop() {
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]; RgbColor pixel((uint8_t)packetBuffer[i+1], (uint8_t)packetBuffer[i+2], (uint8_t)packetBuffer[i+3]);
pixels[N].G = (uint8_t)packetBuffer[i+2]; ledstrip.SetPixelColor(N, pixel);
pixels[N].B = (uint8_t)packetBuffer[i+3]; }
} ledstrip.Show();
ledstrip.show(pixels); Serial.print("/");
#if PRINT_FPS
fpsCounter++;
#endif
} }
#if PRINT_FPS }
if (millis() - secondTimer >= 1000U) {
secondTimer = millis();
Serial.printf("FPS: %d\n", fpsCounter);
fpsCounter = 0;
}
#endif
}