#define IR_1 0x68
#define IR_2 0x98
#define IR_3 0xB0
#define IR_4 0x30
#define IR_5 0x18
#define IR_6 0x7A
#define IR_7 0x10
#define IR_8 0x38
#define IR_9 0x5A
#define IR_STAR 0x42
#define IR_0 0x4A
#define IR_HASH 0x52
#define IR_UP 0x62
#define IR_LEFT 0x22
#define IR_OK 0x2
#define IR_RIGHT 0xC2
#define IR_DOWN 0xA8
#define MY_PERIOD 1500
#include <NecDecoder.h>
NecDecoder ir;
bool oneTouch = 0;
bool twoTouch = 0;
uint8_t region;
uint32_t tmr1;
//Подключаем GyverHC595
#include <GyverHC595.h>
//GyverHC595<10, HC_SPI> reg(10);// аппаратный SPI, скорость 4MHz (по умолч.)
//GyverHC595<10, HC_SPI, 8000000> reg(10); // аппаратный SPI, кастомная скорость
GyverHC595<10, HC_PINS> reg(10, 11, 13); // программный SPI (bit bang)
void setup() {
attachInterrupt(0, irIsr, FALLING);
}
//Активация приема ИК-сигнала
void irIsr() {
ir.tick();
}
void loop() {
if (ir.available()) {
oneTouch = 1; // фиксируем что есть первое нажатие
switch (ir.readCommand()) {
// расшифровка принятого ИК сигнала и присвоение переменной region номера выбранного региона
case IR_1: region=1; break;
case IR_2: region=2; break;
case IR_3: region=3; break;
case IR_4: region=4; break;
case IR_5: region=5; break;
case IR_6: region=6; break;
case IR_7: region=7; break;
case IR_8: region=8; break;
case IR_9: region=9; break;
}
}
//Ждем вторую кнопку
tmr1 = millis(); // Запускаем таймер ожидания 2-й кнопки на время заданное глобальной переменной MY_PERIOD
while (millis() - tmr1 <= MY_PERIOD) {
if(oneTouch == 1){
if (ir.available()) {
tmr1 = millis(); // сброс таймера
switch (ir.readCommand()) {
case IR_1: region=region*10+1; break;
case IR_2: region=region*10+2; break;
case IR_3: region=region*10+3; break;
case IR_4: region=region*10+4; break;
case IR_5: region=region*10+5; break;
case IR_6: region=region*10+6; break;
case IR_7: region=region*10+7; break;
case IR_8: region=region*10+8; break;
case IR_9: region=region*10+9; break;
case IR_0: region=region*10+0; break;
}
}
}
}
///Включаем заданный светодиод
// выключаем все для очистки
if(oneTouch == 1){
for (int thisLed = 0; thisLed < 80; thisLed++) {
reg.set(thisLed);
reg.update();
}
//Включаем заданный светодиод
reg.clear(region-1);
reg.update();
oneTouch = 0;
}
}