#define dly 1
unsigned long tempo;
uint8_t ptr = 1;
uint8_t cpt = 0;
uint8_t row = 0;
unsigned long ledpos = 0;
uint8_t offs = 0;
uint8_t pB = 0;
uint8_t pbTimer;
uint8_t att;
bool mute = false;
uint8_t pos;
uint8_t old_att;
#define IR_RECEIVE_PIN 2
#define DECODE_NEC
#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp> // include the library
//---------------
void readP1()
{
ledpos=0;
if (!mute)
{
ledpos=1UL<<att;
if ((pos == 4) || (pos == 9) || (pos == 14))
ledpos |=1<< (att - 1);
}
}
//-----------
void ledMux1()
{
PORTB = 0xfF;
if (cpt > 4)
{
cpt = 0;
ptr = 1;
row++;
if (row > 3)
row = 0;
}
else
{
if (ledpos&(1UL<<pos))
PORTB = 0xFF & ~ptr;
else
PORTB = 0xff;
cpt++;
ptr <<= 1;
}
}
//---------------------------------
void mux()
{
pB = 0;
switch (row)
{
case 0: PORTD = 0x20;
offs = 0;
if (PIND & 0x10)
pB = 1;
break;
case 1: PORTD = 0x40;
offs = 5;
if (PIND & 0x10)
pB = 2;
break;
case 2: PORTD = 0x80;
offs = 10;
if (PIND & 0x10)
pB = 3;
break;
case 3: PORTD = 0x0;
offs = 15;
break;
}
pos=cpt+offs;
ledMux1();
}
//----------------
//------------
void getIR()
{
if (IrReceiver.decode())
{
uint8_t code = 0;
/*
* Print a summary of received data
*/
if (IrReceiver.decodedIRData.protocol == UNKNOWN)
{
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
// We have an unknown protocol here, print extended info
IrReceiver.printIRResultRawFormatted(&Serial, true);
IrReceiver.resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted()
}
else
{
IrReceiver.resume(); // Early enable receiving of the next IR frame
// IrReceiver.printIRResultShort(&Serial);
// IrReceiver.printIRSendUsage(&Serial);
code = IrReceiver.decodedIRData.command;
//Serial.println(code, HEX);
switch (code)
{
case 2: //0x19 reel
if (att < 19)
att++;
break;
case 0x98: //0x16
if (att > 0)
att--;
break;
case 0x47:
mute = !mute;
Serial.println("IR");
//PORTC = mute;
break;
default:
break;
}
Serial.println(att);
}
}
}
//-----------------------------------------
void setup()
{
Serial.begin(115200);
DDRC = 1;
DDRB = 0xff;
DDRD = 0xFF;
PORTB = 0;
tempo = millis() + dly;
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
}
//--------------------------------
void loop() {
if (millis() > tempo)
{
mux();
tempo = millis() + dly;
readP1();
pbTimer++;
if (pbTimer > 100)
{
pbTimer = 0;
switch (pB)
{
case 1: if (att < 19)
att++;
break;
case 2: if (att > 0)att--;
break;
case 3: mute = !mute;
Serial.println(mute);
PORTC = mute;
break;
}
}
}
getIR();
}