#include <IRremote.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
// const int dataPin = 2; /* DS */
// const int clockPin = 3; /* SHCP */
// const int latchPin = 4; /* STCP */
#define PIN_RECEIVER 3 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
void splash() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(42, 3);
oled.print(F("IRremote"));
}
void button() {
oled.clear();
oled.setCursor(30, 3);
oled.print(F("Press Button"));
}
void setup() {
// pinMode(dataPin, OUTPUT);
// pinMode(clockPin, OUTPUT);
// pinMode(latchPin, OUTPUT);
receiver.enableIRIn(); // Start the receiver
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
oled.clear();
oled.on();
splash();
delay(3000);
oled.clear();
button();
delay(3000);
}
// int pattern = 0b10101010;
void loop() {
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
// digitalWrite(latchPin, LOW);
// shiftOut(dataPin, clockPin, LSBFIRST, pattern);
// digitalWrite(latchPin, HIGH);
// delay(500);
// pattern = ~pattern; // Invert the pattern
void oledPrint(char* text)
{
oled.clear();
oled.setCursor(0, 0);
oled.print("button pressed:");
oled.setCursor(0, 1);
oled.print(text);
oled.print(" code: ");
oled.print(receiver.decodedIRData.command);
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
oledPrint("POWER");
break;
case 226:
oledPrint("MENU");
break;
case 34:
oledPrint("TEST");
break;
case 2:
oledPrint("PLUS");
break;
case 194:
oledPrint("BACK");
break;
case 224:
oledPrint("PREV.");
break;
case 168:
oledPrint("PLAY");
break;
case 144:
oledPrint("NEXT");
break;
case 104:
oledPrint("num: 0");
break;
case 152:
oledPrint("MINUS");
break;
case 176:
oledPrint("key: C");
break;
case 48:
oledPrint("num: 1");
break;
case 24:
oledPrint("num: 2");
break;
case 122:
oledPrint("num: 3");
break;
case 16:
oledPrint("num: 4");
break;
case 56:
oledPrint("num: 5");
break;
case 90:
oledPrint("num: 6");
break;
case 66:
oledPrint("num: 7");
break;
case 74:
oledPrint("num: 8");
break;
case 82:
oledPrint("num: 9");
break;
default:
oled.clear();
oled.print(receiver.decodedIRData.command);
oled.print(" other button");
}
}