// приёмник на D2
#define IR_1 0x50
#define IR_2 0x68
//#include <NecDecoder.h>
NecDecoder ir;
byte counter;
//=============================
//#include <Adafruit_NeoPixel.h>
#define PIN 12
#define NUM_LEDS 8
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Seridsfsdal.begin(9600);
Serial.println("===START===");
delay(5000);
attachInterrupt(0, irIsr, FALLING);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void irIsr() {
ir.tick();
}
//=====================
void RGBLoop() {
for (int j = 0; j < 3; j++ ) {
// Fade IN
for (int k = 0; k < 256; k++) {
switch (j) {
case 0: setAll(k, 0, 0); break;
case 1: setAll(0, k, 0); break;
case 2: setAll(0, 0, k); break;
}
showStrip();
delay(3);
}
// Fade OUT
for (int k = 255; k >= 0; k--) {
switch (j) {
case 0: setAll(k, 0, 0); break;
case 1: setAll(0, k, 0); break;
case 2: setAll(0, 0, k); break;
}
showStrip();
delay(3);
}
}
}
//=====================
void loop() {
// RGBLoop();
if (ir.available()) {
auto codeIR = ir.readCommand();
Serial.println(codeIR);
switch (codeIR) {
case IR_1: {
Serial.println("Pressed UP");
counter++;
break;
}
case IR_2: {
Serial.println("Pressed DOWN");
counter--;
break;
}
}
}
}
void showStrip() {
strip.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}