/*
To load a custom firmware:
1. Press "F1" inside the code editor
2. Choose "Load HEX File and Start Simulation…"
3. Select the desired bin/elf/uf2 file: an application compiled with the ESP-IDF,
MicroPython firmware, etc.
Enjoy!
*/
/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-ws2812b-led-strip
*/
#include <Adafruit_NeoPixel.h>
#include <DIYables_IRcontroller.h> // Library for IR Receiver
#define PIN_WS2812B 16 // The ESP32 pin GPIO16 connected to WS2812B
#define NUM_PIXELS 8 // The number of LEDs (pixels) on WS2812B LED strip
int lights;
int brake;
DIYables_IRcontroller_21 irController(19, 200); // debounce time is 200ms
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
void setup() {
ws2812b.begin(); // initialize WS2812B strip object (REQUIRED)
Serial.begin(9600);
irController.begin();
lights = 0;
brake = 0;
}
void loop() {
ws2812b.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called
// // turn pixels to green one-by-one with delay between each pixel
// for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
// ws2812b.setPixelColor(pixel, ws2812b.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
// ws2812b.show(); // update to the WS2812B Led Strip
// delay(500); // 500ms pause between each pixel
// }
// // turn off all pixels for two seconds
// ws2812b.clear();
// ws2812b.show(); // update to the WS2812B Led Strip
// delay(2000); // 2 seconds off time
// // turn on all pixels to red at the same time for two seconds
// for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel
// ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0)); // it only takes effect if pixels.show() is called
// }
// ws2812b.show(); // update to the WS2812B Led Strip
// delay(1000); // 1 second on time
// // turn off all pixels for one seconds
// ws2812b.clear();
// ws2812b.show(); // update to the WS2812B Led Strip
// delay(1000); // 1 second off time
// IR Remote
Key21 key = irController.getKey();
if (key != Key21::NONE) {
switch (key) {
case Key21::KEY_CH_MINUS:
Serial.println("CH-");
// TODO: YOUR CONTROL
break;
case Key21::KEY_CH:
Serial.println("CH");
// TODO: YOUR CONTROL
break;
case Key21::KEY_CH_PLUS:
Serial.println("CH+");
// TODO: YOUR CONTROL
break;
case Key21::KEY_PREV:
Serial.println("<<");
// TODO: YOUR CONTROL
break;
case Key21::KEY_NEXT:
Serial.println(">>");
// TODO: YOUR CONTROL
break;
case Key21::KEY_PLAY_PAUSE:
Serial.println(">||");
// TODO: YOUR CONTROL
break;
case Key21::KEY_VOL_MINUS:
Serial.println("–");
// TODO: YOUR CONTROL
break;
case Key21::KEY_VOL_PLUS:
Serial.println("+");
// TODO: YOUR CONTROL
break;
case Key21::KEY_EQ:
Serial.println("EQ");
// TODO: YOUR CONTROL
break;
case Key21::KEY_100_PLUS:
Serial.println("100+");
// TODO: YOUR CONTROL
break;
case Key21::KEY_200_PLUS:
Serial.println("200+");
// TODO: YOUR CONTROL
break;
case Key21::KEY_0:
Serial.println("0");
// TODO: YOUR CONTROL
break;
case Key21::KEY_1:
Serial.println("1");
// TODO: YOUR CONTROL
break;
case Key21::KEY_2:
Serial.println("Lights");
if (lights == 0){
ws2812b.setPixelColor(1, ws2812b.Color(255, 255, 255));
ws2812b.setPixelColor(2, ws2812b.Color(255, 255, 255));
ws2812b.show();
lights = 1;
}
else{
lights = 0;
ws2812b.show();
}
break;
case Key21::KEY_3:
Serial.println("3");
// TODO: YOUR CONTROL
break;
case Key21::KEY_4:
Serial.println("4");
// TODO: YOUR CONTROL
break;
case Key21::KEY_5:
Serial.println("5");
// TODO: YOUR CONTROL
break;
case Key21::KEY_6:
Serial.println("6");
// TODO: YOUR CONTROL
break;
case Key21::KEY_7:
Serial.println("7");
// TODO: YOUR CONTROL
break;
case Key21::KEY_8:
Serial.println("8");
// TODO: YOUR CONTROL
break;
case Key21::KEY_9:
Serial.println("9");
if (brake == 0){
ws2812b.setPixelColor(4, ws2812b.Color(255, 0, 0));
ws2812b.setPixelColor(7, ws2812b.Color(255, 0, 0));
ws2812b.show();
brake = 1;
}
else{
brake = 0;
ws2812b.show();
}
break;
default:
Serial.println("WARNING: undefined key:");
break;
}
}
}