From bad8e5166a2f1bbad95a4fb8849b08d1edfc7d3a Mon Sep 17 00:00:00 2001 From: probonopd Date: Thu, 20 Jun 2019 01:13:44 +0000 Subject: [PATCH] Add WS2812B control, closes #126 (#127) --- .travis.yml | 1 + .../ESP8266WirelessPrintAsync.ino | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.travis.yml b/.travis.yml index 78a8f29..11020bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ install: - git clone https://github.com/ayushsharma82/AsyncElegantOTA - git clone -o 1c02154 https://github.com/alanswx/ESPAsyncWiFiManager - ( git clone -b 6.x https://github.com/bblanchon/ArduinoJson ; cd ArduinoJson ; git reset --hard 3df4efd ) + - git clone -o 9619fef https://github.com/Makuna/NeoPixelBus # https://github.com/Makuna/NeoPixelBus/issues/275 - if [[ "$BD" =~ "esp32:esp32:" ]]; then git clone https://github.com/bbx10/Hash_tng ; fi - cd - diff --git a/ESP8266WirelessPrintAsync/ESP8266WirelessPrintAsync.ino b/ESP8266WirelessPrintAsync/ESP8266WirelessPrintAsync.ino index 46dd016..a1ca2f2 100644 --- a/ESP8266WirelessPrintAsync/ESP8266WirelessPrintAsync.ino +++ b/ESP8266WirelessPrintAsync/ESP8266WirelessPrintAsync.ino @@ -18,6 +18,23 @@ #include "CommandQueue.h" +#include + +const uint16_t PixelCount = 20; // this example assumes 4 pixels, making it smaller will cause a failure +const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for ESP8266 (there it is GPIO2 = D4) +#define colorSaturation 255 +RgbColor red(colorSaturation, 0, 0); +RgbColor green(0, colorSaturation, 0); +RgbColor blue(0, 0, colorSaturation); +RgbColor white(colorSaturation); +RgbColor black(0); + +#if defined(ESP8266) + NeoPixelBus strip(PixelCount); // ESP8266 always uses GPIO2 = D4 +#elif defined(ESP32) + NeoPixelBus strip(PixelCount, PixelPin); +#endif + // On ESP8266 use the normal Serial() for now, but name it PrinterSerial for compatibility with ESP32 // On ESP32, use Serial1 (rather than the normal Serial0 which prints stuff during boot that confuses the printer) #ifdef ESP8266 @@ -934,6 +951,18 @@ void ReceiveResponses() { serialResponse = ""; restartSerialTimeout(); } + // this resets all the neopixels to an off state + strip.Begin(); + strip.Show(); + // strip.SetPixelColor(0, red); + // strip.SetPixelColor(1, green); + // strip.SetPixelColor(2, blue); + // strip.SetPixelColor(3, white); + int a; + for(a=0; a