Skip to content

Commit bad8e51

Browse files
authored
Add WS2812B control, closes #126 (#127)
1 parent b65e0b0 commit bad8e51

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ install:
2828
- git clone https://github.com/ayushsharma82/AsyncElegantOTA
2929
- git clone -o 1c02154 https://github.com/alanswx/ESPAsyncWiFiManager
3030
- ( git clone -b 6.x https://github.com/bblanchon/ArduinoJson ; cd ArduinoJson ; git reset --hard 3df4efd )
31+
- git clone -o 9619fef https://github.com/Makuna/NeoPixelBus # https://github.com/Makuna/NeoPixelBus/issues/275
3132
- if [[ "$BD" =~ "esp32:esp32:" ]]; then git clone https://github.com/bbx10/Hash_tng ; fi
3233
- cd -
3334

ESP8266WirelessPrintAsync/ESP8266WirelessPrintAsync.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818

1919
#include "CommandQueue.h"
2020

21+
#include <NeoPixelBus.h>
22+
23+
const uint16_t PixelCount = 20; // this example assumes 4 pixels, making it smaller will cause a failure
24+
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for ESP8266 (there it is GPIO2 = D4)
25+
#define colorSaturation 255
26+
RgbColor red(colorSaturation, 0, 0);
27+
RgbColor green(0, colorSaturation, 0);
28+
RgbColor blue(0, 0, colorSaturation);
29+
RgbColor white(colorSaturation);
30+
RgbColor black(0);
31+
32+
#if defined(ESP8266)
33+
NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart1Ws2813Method> strip(PixelCount); // ESP8266 always uses GPIO2 = D4
34+
#elif defined(ESP32)
35+
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
36+
#endif
37+
2138
// On ESP8266 use the normal Serial() for now, but name it PrinterSerial for compatibility with ESP32
2239
// On ESP32, use Serial1 (rather than the normal Serial0 which prints stuff during boot that confuses the printer)
2340
#ifdef ESP8266
@@ -934,6 +951,18 @@ void ReceiveResponses() {
934951
serialResponse = "";
935952
restartSerialTimeout();
936953
}
954+
// this resets all the neopixels to an off state
955+
strip.Begin();
956+
strip.Show();
957+
// strip.SetPixelColor(0, red);
958+
// strip.SetPixelColor(1, green);
959+
// strip.SetPixelColor(2, blue);
960+
// strip.SetPixelColor(3, white);
961+
int a;
962+
for(a=0; a<PixelCount; a++){
963+
strip.SetPixelColor(a, white);
964+
}
965+
strip.Show();
937966
}
938967

939968

0 commit comments

Comments
 (0)