Created
May 28, 2020 21:08
-
-
Save baqwas/7843b78c48d4747715f056b7e8a4f99c to your computer and use it in GitHub Desktop.
NodeMCU to WS2813 using FastLED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SoundDetection.ino | |
* An introductory example to process data from a sound sensor using NodeMCU ESP8266 12E | |
* | |
* 2020-05-20 armw v0.1 initial DRAFT | |
* | |
* Operations: | |
* The WS2813 is a 3-wire chipset that combines the LED and its controller in a single | |
* package. | |
* | |
* Method: | |
* setup() - run once | |
* loop() - run many | |
* SoundDetectionISR() - interrupt handler | |
* | |
* Notes: | |
* Since the program has only one dedicated processing requirement (i.e. convert sound | |
* to visualization instructions), there is no consideration for any parallel activity | |
* using alternate scheme for timing delays. | |
* | |
* NodeMCU pinout | |
* #define PIN_WIRE_SDA (4) | |
* #define PIN_WIRE_SCL (5) | |
* | |
* static const uint8_t SDA = PIN_WIRE_SDA; | |
* static const uint8_t SCL = PIN_WIRE_SCL; | |
* | |
* static const uint8_t LED_BUILTIN = 16; | |
* static const uint8_t BUILTIN_LED = 16; // on-board LED | |
* static const uint8_t D0 = 16; | |
* static const uint8_t D1 = 5; | |
* static const uint8_t D2 = 4; // on-board LED | |
* static const uint8_t D3 = 0; | |
* static const uint8_t D4 = 2; | |
* static const uint8_t D5 = 14; | |
* static const uint8_t D6 = 12; | |
* static const uint8_t D7 = 13; | |
* static const uint8_t D8 = 15; | |
* static const uint8_t D9 = 3; | |
* static const uint8_t D10 = 1; | |
* | |
* WS2813 pinout | |
* 4 DIN -> <- 3 DO | |
* 5 GND -> <- 2 VDD | |
* 6 BIN -> <- 1 VCC | |
* | |
* References: | |
* https://learn.sparkfun.com/tutorials/interactive-led-music-visualizer/all | |
* https://github.com/bartlettmic/SparkFun-RGB-LED-Music-Sound-Visualizer-Arduino-Code/blob/master/code%20math.md | |
* https://www.elecrow.com/download/WS2813_LED_Datasheet.pdf | |
* http://fastled.io/ | |
* https://github.com/FastLED/FastLED | |
* https://github.com/FastLED/FastLED/wiki/ESP8266-notes | |
*/ | |
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER// MUST precede the following statement; see EP8266 notes | |
#include <FastLED.h> | |
// NodeMCU ESP8266 12E board parameters | |
const int pinLED = LED_BUILTIN; // GPIO16, D0, USER, WAKE | |
// WS2813 strip LED parameters | |
#define LED_TYPE WS2813 | |
#define COLOR_ORDER GRB | |
#define NUM_LEDS 300 // number of LEDs in strip | |
#define pinDATA D4 // GPIO5 | |
CRGB myLEDs[NUM_LEDS]; // instantiate entity for strip | |
void setup() | |
{ | |
pinMode(pinLED, OUTPUT); // nominal status using default LED | |
delay(1000); // just to ensure warm-up | |
} | |
void loop() | |
{ | |
myLEDs[0] = CRGB::Red; | |
FastLED.show(); | |
delay(3000); | |
myLEDs[0] = CRGB::Black; | |
FastLED.show(); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment