From a4984480f4091669af1fbb60fb1694d9d9e06e1b Mon Sep 17 00:00:00 2001 From: Bl4d3s Date: Sat, 25 Feb 2017 16:13:17 -0600 Subject: [PATCH 1/5] Hue+ channel selection, fix Hue+ flickering bug (pull request #97) from Bl4d3s/KeyboardVisualizer --- KeyboardVisualizerCommon/LEDStrip.cpp | 36 +++++++++++++++++++++------ KeyboardVisualizerCommon/LEDStrip.h | 2 ++ KeyboardVisualizerQT/main.cpp | 15 +++++------ KeyboardVisualizerVC/main.cpp | 15 +++++------ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/KeyboardVisualizerCommon/LEDStrip.cpp b/KeyboardVisualizerCommon/LEDStrip.cpp index 9950659..3369a60 100644 --- a/KeyboardVisualizerCommon/LEDStrip.cpp +++ b/KeyboardVisualizerCommon/LEDStrip.cpp @@ -90,15 +90,37 @@ void LEDStrip::InitializeHuePlus(char* ledstring) strcpy(led_string, ledstring); LPSTR source = NULL; + LPSTR channels = NULL; LPSTR numleds = NULL; LPSTR next = NULL; source = strtok_s(ledstring, ",", &next); + //Check for selected channel 0=both, 1= Ch.1, 2= Ch.2 + if (strlen(next)) + { + channels = strtok_s(next, ",", &next); + } + + switch (atoi(channels)) + { + case 0: + channel = 0x00; + break; + + case 1: + channel = 0x01; + break; + + case 2: + channel = 0x02; + break; + } + //Check for the number of LEDs, sets the corresponding variable with the counter for the fans if (strlen(next)) { - numleds = strtok_s(next, ",", &next); + numleds = strtok_s(next, ",", &next); } switch (atoi(numleds) / 8) @@ -275,16 +297,16 @@ void LEDStrip::SetLEDsHuePlus(COLORREF pixels[64][256]) { unsigned char *serial_buf; - serial_buf = new unsigned char[250]; //Size of Message always 5 XX Blocks (Mode Selection) + 3 XX for each LED (1 color) - //-> max of 40 LEDs per Channel (or 5 Fans a 8 LEDs) -> 125 Blocks (empty LEDs are written, too) + serial_buf = new unsigned char[hueSize]; //Size of Message always 5 XX Blocks (Mode Selection) + 3 XX for each LED (1 color) + //-> max of 40 LEDs per Channel (or 5 Fans a 8 LEDs) -> 125 Blocks (empty LEDs are written, too serial_buf[0] = 0x4b; - serial_buf[1] = 0x00; - serial_buf[2] = 0x0e; + serial_buf[1] = channel; + serial_buf[2] = 0x0e; serial_buf[3] = fans; serial_buf[4] = 0x00; - for (int i = 5; i < 250; i++) + for (int i = 5; i < hueSize; i++) { //clearing the buf otherwise sometimes strange things are written to the COM Port serial_buf[i] = 0x00; @@ -299,7 +321,7 @@ void LEDStrip::SetLEDsHuePlus(COLORREF pixels[64][256]) serial_buf[idx + 7] = GetBValue(color); } - serialport->serial_write((char *)serial_buf,250); + serialport->serial_write((char *)serial_buf, hueSize); serialport->serial_flush_tx(); delete[] serial_buf; diff --git a/KeyboardVisualizerCommon/LEDStrip.h b/KeyboardVisualizerCommon/LEDStrip.h index c7a845a..01e2176 100644 --- a/KeyboardVisualizerCommon/LEDStrip.h +++ b/KeyboardVisualizerCommon/LEDStrip.h @@ -37,6 +37,8 @@ class LEDStrip int baud_rate; int num_leds; int fans; + int channel; + const int hueSize = 125; int * LEDStripXIndex; int * LEDStripYIndex; diff --git a/KeyboardVisualizerQT/main.cpp b/KeyboardVisualizerQT/main.cpp index cd5e090..5b3c18d 100644 --- a/KeyboardVisualizerQT/main.cpp +++ b/KeyboardVisualizerQT/main.cpp @@ -245,13 +245,14 @@ bool parse_command_line(int argc, char *argv[]) printf(" - UDP : ledstrip=udp:client,port,num_leds\r\n"); printf(" - (ex.ledstrip=udp:192.168.1.5,1234,30)\r\n"); printf(" xmas - COM port, ex. xmas=COM2\r\n"); - printf(" hueplus - HUE+ config:\r\n"); - printf(" - hueplus=port,num_leds\r\n"); - printf(" - num_leds: Fans * 8 ex. 3 Fans -> 24\r\n"); - printf(" - Important for Fans: If you have connected fans on both channels only count the fans on the channel with the most fans\r\n"); - printf(" ex. 3 Fans on Ch. 1 4 Fans on CH. 2: num_leds 32 for the 4 Fans\r\n"); - printf(" For best Visualizer results don`t connect on one channel 3 fans more than on the other channel\r\n"); - printf(" - (ex. hueplus=COM4,24\r\n"); + printf(" hueplus - HUE+ config:\r\n"); + printf(" - hueplus=port,channel,num_leds\r\n"); + printf(" - channel: 0 -> both channels, 1 -> channel 1, 2 -> channel 2\r\n"); + printf(" - num_leds: Fans * 8 ex. 3 Fans -> 24\r\n"); + printf(" - Important for Fans: If you have connected fans on both channels only count the fans on the channel with the most fans\r\n"); + printf(" ex. 3 Fans on Ch. 1 4 Fans on CH. 2: num_leds 32 for the 4 Fans\r\n"); + printf(" For best Visualizer results don`t connect on one channel 3 fans more than on the other channel\r\n"); + printf(" - (ex. hueplus=COM4,1,24\r\n"); return false; } diff --git a/KeyboardVisualizerVC/main.cpp b/KeyboardVisualizerVC/main.cpp index 989bda0..6936b59 100644 --- a/KeyboardVisualizerVC/main.cpp +++ b/KeyboardVisualizerVC/main.cpp @@ -280,13 +280,14 @@ boolean parse_command_line(char * command_line) printf(" - UDP : ledstrip=udp:client,port,num_leds\r\n"); printf(" - (ex.ledstrip=udp:192.168.1.5,1234,30)\r\n"); printf(" xmas - COM port, ex. xmas=COM2\r\n"); - printf(" hueplus - HUE+ config:\r\n"); - printf(" - hueplus=port,num_leds\r\n"); - printf(" - num_leds: Fans * 8 ex. 3 Fans -> 24\r\n"); - printf(" - Important for Fans: If you have connected fans on both channels only count the fans on the channel with the most fans\r\n"); - printf(" ex. 3 Fans on Ch. 1 4 Fans on CH. 2: num_leds 32 for the 4 Fans\r\n"); - printf(" For best Visualizer results don`t connect on one channel 3 fans more than on the other channel\r\n"); - printf(" - (ex. hueplus=COM4,24\r\n"); + printf(" hueplus - HUE+ config:\r\n"); + printf(" - hueplus=port,channel,num_leds\r\n"); + printf(" - channel: 0 -> both channels, 1 -> channel 1, 2 -> channel 2\r\n"); + printf(" - num_leds: Fans * 8 ex. 3 Fans -> 24\r\n"); + printf(" - Important for Fans: If you have connected fans on both channels only count the fans on the channel with the most fans\r\n"); + printf(" ex. 3 Fans on Ch. 1 4 Fans on CH. 2: num_leds 32 for the 4 Fans\r\n"); + printf(" For best Visualizer results don`t connect on one channel 3 fans more than on the other channel\r\n"); + printf(" - (ex. hueplus=COM4,1,24\r\n"); return FALSE; } From 5d42db8fbe14ec8d6d7447a91cae3f2e08b07a44 Mon Sep 17 00:00:00 2001 From: Bl4d3s Date: Mon, 20 Mar 2017 01:23:02 +0100 Subject: [PATCH 2/5] Added Arduino sketches Black: LEDs switched off, FadeOut: LEDs fade Out from current color (slowly and not completly smooth) --- .../WS2812B_LEDStrip_Arduino_Black.ino | 128 ++++++++++++++++ .../WS2812B_LEDStrip_Arduino_FadeOut.ino | 144 ++++++++++++++++++ ...WS2812B_LEDStrip_Arduino_FastLED_Black.ino | 120 +++++++++++++++ ...2812B_LEDStrip_Arduino_FastLED_FadeOut.ino | 120 +++++++++++++++ .../WS2812B_LEDStrip_ESP8266_Black.ino | 112 ++++++++++++++ .../WS2812B_LEDStrip_ESP8266_FadeOut.ino | 127 +++++++++++++++ 6 files changed, 751 insertions(+) create mode 100644 WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_Black.ino create mode 100644 WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_FadeOut.ino create mode 100644 WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_Black.ino create mode 100644 WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_FadeOut.ino create mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino create mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino diff --git a/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_Black.ino b/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_Black.ino new file mode 100644 index 0000000..7878e4b --- /dev/null +++ b/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_Black.ino @@ -0,0 +1,128 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ +#include +#ifdef __AVR__ + #include +#endif + +#define PIN 10 +#define LEDS 54 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across +// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input +// and minimize distance between Arduino and first pixel. Avoid connecting +// on a live circuit...if you must, connect GND first. +unsigned char serial_buffer[PACKET_SZ]; +unsigned int head = 0; +unsigned int start; +unsigned int checksum_1; +unsigned int checksum_0; +unsigned long previousMillis; + +void setup() +{ + Serial.begin(115200); + strip.begin(); + strip.show(); + previousMillis = millis(); +} + +void loop() +{ + if( Serial.available()) + { + + serial_buffer[head] = Serial.read(); + + if( head >= (PACKET_SZ - 1) ) + { + start = 0; + checksum_1 = head; + checksum_0 = head - 1; + head = 0; + } + else + { + start = head + 1; + checksum_1 = head; + if( head == 0 ) + { + checksum_0 = PACKET_SZ - 1; + } + else + { + checksum_0 = head - 1; + } + head++; + } + + if( serial_buffer[start] == 0xAA ) + { + unsigned short sum = 0; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += serial_buffer[i]; + } + + if( start > 0 ) + { + for( int i = start; i < PACKET_SZ; i++ ) + { + sum += serial_buffer[i]; + } + } + + //Test if valid write packet + if( ( ( (unsigned short)serial_buffer[checksum_0] << 8 ) | serial_buffer[checksum_1] ) == sum ) + { + noInterrupts(); + for( int i = 0; i < LEDS; i++ ) + { + int idx = start + 1 + ( 3 * i ); + + if( idx >= (PACKET_SZ - 1) ) + { + idx = idx - PACKET_SZ; + } + + strip.setPixelColor(i, strip.Color(serial_buffer[idx], serial_buffer[idx+1], serial_buffer[idx+2])); + + } + previousMillis = millis(); + strip.show(); + interrupts(); + + } + } + } + if ((millis() - previousMillis) > 1000) + { + for( int i = 0; i < LEDS; i++ ) + { + strip.setPixelColor(i, strip.Color(0,0,0)); + } + strip.show(); + previousMillis=millis(); + } +} + + + + diff --git a/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_FadeOut.ino b/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_FadeOut.ino new file mode 100644 index 0000000..55eeff6 --- /dev/null +++ b/WS2812B_LEDStrip_Arduino/WS2812B_LEDStrip_Arduino_FadeOut.ino @@ -0,0 +1,144 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ +#include +#ifdef __AVR__ + #include +#endif + +#define PIN 10 +#define LEDS 54 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across +// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input +// and minimize distance between Arduino and first pixel. Avoid connecting +// on a live circuit...if you must, connect GND first. +unsigned char serial_buffer[PACKET_SZ]; +unsigned int head = 0; +unsigned int start; +unsigned int checksum_1; +unsigned int checksum_0; +unsigned long previousMillis; + +void setup() +{ + Serial.begin(115200); + strip.begin(); + strip.show(); + previousMillis = millis(); +} + +void loop() +{ + if( Serial.available()) + { + + serial_buffer[head] = Serial.read(); + + if( head >= (PACKET_SZ - 1) ) + { + start = 0; + checksum_1 = head; + checksum_0 = head - 1; + head = 0; + } + else + { + start = head + 1; + checksum_1 = head; + if( head == 0 ) + { + checksum_0 = PACKET_SZ - 1; + } + else + { + checksum_0 = head - 1; + } + head++; + } + + if( serial_buffer[start] == 0xAA ) + { + unsigned short sum = 0; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += serial_buffer[i]; + } + + if( start > 0 ) + { + for( int i = start; i < PACKET_SZ; i++ ) + { + sum += serial_buffer[i]; + } + } + + //Test if valid write packet + if( ( ( (unsigned short)serial_buffer[checksum_0] << 8 ) | serial_buffer[checksum_1] ) == sum ) + { + noInterrupts(); + for( int i = 0; i < LEDS; i++ ) + { + int idx = start + 1 + ( 3 * i ); + + if( idx >= (PACKET_SZ - 1) ) + { + idx = idx - PACKET_SZ; + } + + strip.setPixelColor(i, strip.Color(serial_buffer[idx], serial_buffer[idx+1], serial_buffer[idx+2])); + + } + previousMillis = millis(); + strip.show(); + interrupts(); + + } + } + } + if ((millis() - previousMillis) > 1000) + { + bool black = false; + uint32_t colorBlack = strip.Color(0,0,0); + while (!black) + { + for( int i = 0; i < LEDS; i++ ) + { + if ( colorBlack != strip.getPixelColor(i)) + { + uint32_t c = strip.getPixelColor(i); + int r = (uint8_t)(c >> 16); + int g = (uint8_t)(c >> 8); + int b = (uint8_t)c; + strip.setPixelColor(i, strip.Color(r*0.8,g*0.8,b*0.8)); + } + else + { + black = true; + } + } + strip.show(); + } + previousMillis=millis(); + } +} + + + + diff --git a/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_Black.ino b/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_Black.ino new file mode 100644 index 0000000..58afbc8 --- /dev/null +++ b/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_Black.ino @@ -0,0 +1,120 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (FastLED) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ +#include "FastLED.h" +#ifdef __AVR__ + #include +#endif + +#define PIN 10 +#define LEDS 54 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +CRGB leds[LEDS]; +unsigned char serial_buffer[PACKET_SZ]; +unsigned int head = 0; +unsigned int start; +unsigned int checksum_1; +unsigned int checksum_0; +unsigned long previousMillis; + +void setup() +{ + FastLED.addLeds(leds, LEDS); + for( int i = 0; i < LEDS; i++ ) + { + leds[i] = CRGB::Black; + } + FastLED.show(); + + Serial.begin(115200); + previousMillis = millis(); +} + +void loop() +{ + if( Serial.available() ) + { + serial_buffer[head] = Serial.read(); + + if( head >= (PACKET_SZ - 1) ) + { + start = 0; + checksum_1 = head; + checksum_0 = head - 1; + head = 0; + } + else + { + start = head + 1; + checksum_1 = head; + if( head == 0 ) + { + checksum_0 = PACKET_SZ - 1; + } + else + { + checksum_0 = head - 1; + } + head++; + } + + if( serial_buffer[start] == 0xAA ) + { + unsigned short sum = 0; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += serial_buffer[i]; + } + + if( start > 0 ) + { + for( int i = start; i < PACKET_SZ; i++ ) + { + sum += serial_buffer[i]; + } + } + + //Test if valid write packet + if( ( ( (unsigned short)serial_buffer[checksum_0] << 8 ) | serial_buffer[checksum_1] ) == sum ) + { + noInterrupts(); + for( int i = 0; i < LEDS; i++ ) + { + int idx = start + 1 + ( 3 * i ); + + if( idx >= (PACKET_SZ - 1) ) + { + idx = idx - PACKET_SZ; + } + + leds[i].g = serial_buffer[idx]; + leds[i].r = serial_buffer[idx+1]; + leds[i].b = serial_buffer[idx+2]; + } + + previousMillis = millis(); + FastLED.show(); + interrupts(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + for (int k = 0; k < 16; k++) + { + for( int i = 0; i < LEDS; i++ ) + { + leds[i].nscale8(232); + } + FastLED.show(); + } + previousMillis = millis(); + } +} diff --git a/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_FadeOut.ino b/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_FadeOut.ino new file mode 100644 index 0000000..58afbc8 --- /dev/null +++ b/WS2812B_LEDStrip_Arduino_FastLED/WS2812B_LEDStrip_Arduino_FastLED_FadeOut.ino @@ -0,0 +1,120 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (FastLED) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ +#include "FastLED.h" +#ifdef __AVR__ + #include +#endif + +#define PIN 10 +#define LEDS 54 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +CRGB leds[LEDS]; +unsigned char serial_buffer[PACKET_SZ]; +unsigned int head = 0; +unsigned int start; +unsigned int checksum_1; +unsigned int checksum_0; +unsigned long previousMillis; + +void setup() +{ + FastLED.addLeds(leds, LEDS); + for( int i = 0; i < LEDS; i++ ) + { + leds[i] = CRGB::Black; + } + FastLED.show(); + + Serial.begin(115200); + previousMillis = millis(); +} + +void loop() +{ + if( Serial.available() ) + { + serial_buffer[head] = Serial.read(); + + if( head >= (PACKET_SZ - 1) ) + { + start = 0; + checksum_1 = head; + checksum_0 = head - 1; + head = 0; + } + else + { + start = head + 1; + checksum_1 = head; + if( head == 0 ) + { + checksum_0 = PACKET_SZ - 1; + } + else + { + checksum_0 = head - 1; + } + head++; + } + + if( serial_buffer[start] == 0xAA ) + { + unsigned short sum = 0; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += serial_buffer[i]; + } + + if( start > 0 ) + { + for( int i = start; i < PACKET_SZ; i++ ) + { + sum += serial_buffer[i]; + } + } + + //Test if valid write packet + if( ( ( (unsigned short)serial_buffer[checksum_0] << 8 ) | serial_buffer[checksum_1] ) == sum ) + { + noInterrupts(); + for( int i = 0; i < LEDS; i++ ) + { + int idx = start + 1 + ( 3 * i ); + + if( idx >= (PACKET_SZ - 1) ) + { + idx = idx - PACKET_SZ; + } + + leds[i].g = serial_buffer[idx]; + leds[i].r = serial_buffer[idx+1]; + leds[i].b = serial_buffer[idx+2]; + } + + previousMillis = millis(); + FastLED.show(); + interrupts(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + for (int k = 0; k < 16; k++) + { + for( int i = 0; i < LEDS; i++ ) + { + leds[i].nscale8(232); + } + FastLED.show(); + } + previousMillis = millis(); + } +} diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino new file mode 100644 index 0000000..d7fd002 --- /dev/null +++ b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino @@ -0,0 +1,112 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ + +#include +#include +#include + +const char* ssid = "ASUS_RPAC68U"; +const char* password = "DerHobbit123"; + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +char packet_buf[1024]; +unsigned long previousMillis; + +#define PIN 13 +#define LEDS 68 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() +{ + Serial.begin(115200); + delay(10); + + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Udp.begin(12345); + strip.begin(); + previousMillis = millis(); +} + +int value = 0; + +void loop() +{ + int noBytes = Udp.parsePacket(); + + if( noBytes ) + { + Serial.print("Received "); + Serial.print(noBytes); + Serial.print(" bytes\r\n"); + Udp.read(packet_buf, noBytes); + + if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) + { + unsigned short sum = 0; + int checksum_0 = PACKET_SZ - 2; + int checksum_1 = PACKET_SZ - 1; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += packet_buf[i]; + } + + //Test if valid write packet + if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) + { + for( int i = 0; i < LEDS; i++ ) + { + int idx = 1 + ( 3 * i ); + + strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); + } + previousMillis = millis(); + strip.show(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + for( int i = 0; i < LEDS; i++ ) + { + strip.setPixelColor(i, strip.Color(0,0,0)); + } + strip.show(); + previousMillis=millis(); + } + +} + diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino new file mode 100644 index 0000000..6436591 --- /dev/null +++ b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino @@ -0,0 +1,127 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ + +#include +#include +#include + +const char* ssid = "ASUS_RPAC68U"; +const char* password = "DerHobbit123"; + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +char packet_buf[1024]; +unsigned long previousMillis; + +#define PIN 13 +#define LEDS 68 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() +{ + Serial.begin(115200); + delay(10); + + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Udp.begin(12345); + strip.begin(); + previousMillis = millis(); +} + +int value = 0; + +void loop() +{ + int noBytes = Udp.parsePacket(); + + if( noBytes ) + { + Serial.print("Received "); + Serial.print(noBytes); + Serial.print(" bytes\r\n"); + Udp.read(packet_buf, noBytes); + + if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) + { + unsigned short sum = 0; + int checksum_0 = PACKET_SZ - 2; + int checksum_1 = PACKET_SZ - 1; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += packet_buf[i]; + } + + //Test if valid write packet + if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) + { + for( int i = 0; i < LEDS; i++ ) + { + int idx = 1 + ( 3 * i ); + + strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); + } + previousMillis = millis(); + strip.show(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + bool black = false; + uint32_t colorBlack = strip.Color(0,0,0); + while (!black) + { + for( int i = 0; i < LEDS; i++ ) + { + if ( colorBlack != strip.getPixelColor(i)) + { + uint32_t c = strip.getPixelColor(i); + int r = (uint8_t)(c >> 16); + int g = (uint8_t)(c >> 8); + int b = (uint8_t)c; + strip.setPixelColor(i, strip.Color(r*0.8,g*0.8,b*0.8)); + } + else + { + black = true; + } + } + strip.show(); + } + previousMillis=millis(); + } +} + From 55da6078df0c36824112187cf074071a82ebdd24 Mon Sep 17 00:00:00 2001 From: Bl4d3s Date: Mon, 20 Mar 2017 01:27:21 +0100 Subject: [PATCH 3/5] Delete WS2812B_LEDStrip_ESP8266_Black.ino --- .../WS2812B_LEDStrip_ESP8266_Black.ino | 112 ------------------ 1 file changed, 112 deletions(-) delete mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino deleted file mode 100644 index d7fd002..0000000 --- a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino +++ /dev/null @@ -1,112 +0,0 @@ -/*---------------------------------------------------------*\ -| | -| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | -| for use with Keyboard Visualizer VCUI | -| | -| Adam Honse (calcprogrammer1) 12/9/2016 | -| | -\*---------------------------------------------------------*/ - -#include -#include -#include - -const char* ssid = "ASUS_RPAC68U"; -const char* password = "DerHobbit123"; - -// A UDP instance to let us send and receive packets over UDP -WiFiUDP Udp; - -char packet_buf[1024]; -unsigned long previousMillis; - -#define PIN 13 -#define LEDS 68 -#define PACKET_SZ ( (LEDS * 3) + 3 ) - -// Parameter 1 = number of pixels in strip -// Parameter 2 = Arduino pin number (most are valid) -// Parameter 3 = pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); - -void setup() -{ - Serial.begin(115200); - delay(10); - - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Udp.begin(12345); - strip.begin(); - previousMillis = millis(); -} - -int value = 0; - -void loop() -{ - int noBytes = Udp.parsePacket(); - - if( noBytes ) - { - Serial.print("Received "); - Serial.print(noBytes); - Serial.print(" bytes\r\n"); - Udp.read(packet_buf, noBytes); - - if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) - { - unsigned short sum = 0; - int checksum_0 = PACKET_SZ - 2; - int checksum_1 = PACKET_SZ - 1; - - for( int i = 0; i < checksum_0; i++ ) - { - sum += packet_buf[i]; - } - - //Test if valid write packet - if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) - { - for( int i = 0; i < LEDS; i++ ) - { - int idx = 1 + ( 3 * i ); - - strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); - } - previousMillis = millis(); - strip.show(); - } - } - } - if ((millis() - previousMillis) > 1000) - { - for( int i = 0; i < LEDS; i++ ) - { - strip.setPixelColor(i, strip.Color(0,0,0)); - } - strip.show(); - previousMillis=millis(); - } - -} - From e27e3c14a4586197682c4d2eb59267320be0ff2d Mon Sep 17 00:00:00 2001 From: Bl4d3s Date: Mon, 20 Mar 2017 01:27:31 +0100 Subject: [PATCH 4/5] Delete WS2812B_LEDStrip_ESP8266_FadeOut.ino --- .../WS2812B_LEDStrip_ESP8266_FadeOut.ino | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino deleted file mode 100644 index 6436591..0000000 --- a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino +++ /dev/null @@ -1,127 +0,0 @@ -/*---------------------------------------------------------*\ -| | -| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | -| for use with Keyboard Visualizer VCUI | -| | -| Adam Honse (calcprogrammer1) 12/9/2016 | -| | -\*---------------------------------------------------------*/ - -#include -#include -#include - -const char* ssid = "ASUS_RPAC68U"; -const char* password = "DerHobbit123"; - -// A UDP instance to let us send and receive packets over UDP -WiFiUDP Udp; - -char packet_buf[1024]; -unsigned long previousMillis; - -#define PIN 13 -#define LEDS 68 -#define PACKET_SZ ( (LEDS * 3) + 3 ) - -// Parameter 1 = number of pixels in strip -// Parameter 2 = Arduino pin number (most are valid) -// Parameter 3 = pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); - -void setup() -{ - Serial.begin(115200); - delay(10); - - // We start by connecting to a WiFi network - Serial.println(); - Serial.println(); - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); - Udp.begin(12345); - strip.begin(); - previousMillis = millis(); -} - -int value = 0; - -void loop() -{ - int noBytes = Udp.parsePacket(); - - if( noBytes ) - { - Serial.print("Received "); - Serial.print(noBytes); - Serial.print(" bytes\r\n"); - Udp.read(packet_buf, noBytes); - - if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) - { - unsigned short sum = 0; - int checksum_0 = PACKET_SZ - 2; - int checksum_1 = PACKET_SZ - 1; - - for( int i = 0; i < checksum_0; i++ ) - { - sum += packet_buf[i]; - } - - //Test if valid write packet - if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) - { - for( int i = 0; i < LEDS; i++ ) - { - int idx = 1 + ( 3 * i ); - - strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); - } - previousMillis = millis(); - strip.show(); - } - } - } - if ((millis() - previousMillis) > 1000) - { - bool black = false; - uint32_t colorBlack = strip.Color(0,0,0); - while (!black) - { - for( int i = 0; i < LEDS; i++ ) - { - if ( colorBlack != strip.getPixelColor(i)) - { - uint32_t c = strip.getPixelColor(i); - int r = (uint8_t)(c >> 16); - int g = (uint8_t)(c >> 8); - int b = (uint8_t)c; - strip.setPixelColor(i, strip.Color(r*0.8,g*0.8,b*0.8)); - } - else - { - black = true; - } - } - strip.show(); - } - previousMillis=millis(); - } -} - From 8cb811b41d8ac1318bbb089349ae4e20f9fe9b21 Mon Sep 17 00:00:00 2001 From: Bl4d3s Date: Mon, 20 Mar 2017 01:27:41 +0100 Subject: [PATCH 5/5] Add files via upload --- .../WS2812B_LEDStrip_ESP8266_Black.ino | 112 +++++++++++++++ .../WS2812B_LEDStrip_ESP8266_FadeOut.ino | 127 ++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino create mode 100644 WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino new file mode 100644 index 0000000..1175b0e --- /dev/null +++ b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_Black.ino @@ -0,0 +1,112 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ + +#include +#include +#include + +const char* ssid = ""; +const char* password = ""; + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +char packet_buf[1024]; +unsigned long previousMillis; + +#define PIN 13 +#define LEDS 68 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() +{ + Serial.begin(115200); + delay(10); + + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Udp.begin(1234); + strip.begin(); + previousMillis = millis(); +} + +int value = 0; + +void loop() +{ + int noBytes = Udp.parsePacket(); + + if( noBytes ) + { + Serial.print("Received "); + Serial.print(noBytes); + Serial.print(" bytes\r\n"); + Udp.read(packet_buf, noBytes); + + if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) + { + unsigned short sum = 0; + int checksum_0 = PACKET_SZ - 2; + int checksum_1 = PACKET_SZ - 1; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += packet_buf[i]; + } + + //Test if valid write packet + if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) + { + for( int i = 0; i < LEDS; i++ ) + { + int idx = 1 + ( 3 * i ); + + strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); + } + previousMillis = millis(); + strip.show(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + for( int i = 0; i < LEDS; i++ ) + { + strip.setPixelColor(i, strip.Color(0,0,0)); + } + strip.show(); + previousMillis=millis(); + } + +} + diff --git a/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino new file mode 100644 index 0000000..d8839fd --- /dev/null +++ b/WS2812B_LEDStrip_ESP8266/WS2812B_LEDStrip_ESP8266_FadeOut.ino @@ -0,0 +1,127 @@ +/*---------------------------------------------------------*\ +| | +| WS2812B (NeoPixel) Serial Controlled LED Strip Driver | +| for use with Keyboard Visualizer VCUI | +| | +| Adam Honse (calcprogrammer1) 12/9/2016 | +| | +\*---------------------------------------------------------*/ + +#include +#include +#include + +const char* ssid = ""; +const char* password = ""; + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +char packet_buf[1024]; +unsigned long previousMillis; + +#define PIN 13 +#define LEDS 68 +#define PACKET_SZ ( (LEDS * 3) + 3 ) + +// Parameter 1 = number of pixels in strip +// Parameter 2 = Arduino pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() +{ + Serial.begin(115200); + delay(10); + + // We start by connecting to a WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + Udp.begin(1234); + strip.begin(); + previousMillis = millis(); +} + +int value = 0; + +void loop() +{ + int noBytes = Udp.parsePacket(); + + if( noBytes ) + { + Serial.print("Received "); + Serial.print(noBytes); + Serial.print(" bytes\r\n"); + Udp.read(packet_buf, noBytes); + + if( noBytes == PACKET_SZ && packet_buf[0] == 0xAA ) + { + unsigned short sum = 0; + int checksum_0 = PACKET_SZ - 2; + int checksum_1 = PACKET_SZ - 1; + + for( int i = 0; i < checksum_0; i++ ) + { + sum += packet_buf[i]; + } + + //Test if valid write packet + if( ( ( (unsigned short)packet_buf[checksum_0] << 8 ) | packet_buf[checksum_1] ) == sum ) + { + for( int i = 0; i < LEDS; i++ ) + { + int idx = 1 + ( 3 * i ); + + strip.setPixelColor(i, strip.Color(packet_buf[idx], packet_buf[idx+1], packet_buf[idx+2])); + } + previousMillis = millis(); + strip.show(); + } + } + } + if ((millis() - previousMillis) > 1000) + { + bool black = false; + uint32_t colorBlack = strip.Color(0,0,0); + while (!black) + { + for( int i = 0; i < LEDS; i++ ) + { + if ( colorBlack != strip.getPixelColor(i)) + { + uint32_t c = strip.getPixelColor(i); + int r = (uint8_t)(c >> 16); + int g = (uint8_t)(c >> 8); + int b = (uint8_t)c; + strip.setPixelColor(i, strip.Color(r*0.8,g*0.8,b*0.8)); + } + else + { + black = true; + } + } + strip.show(); + } + previousMillis=millis(); + } +} +