Skip to content

Instantly share code, notes, and snippets.

@phaer
Last active January 14, 2017 22:10
Show Gist options
  • Save phaer/a16a33b4efd050f69824cf5267bcab5b to your computer and use it in GitHub Desktop.
Save phaer/a16a33b4efd050f69824cf5267bcab5b to your computer and use it in GitHub Desktop.
Metalab Teletext Remote control code.
#include <IRremote.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
// define the symbols of the buttons on the keypads.
const char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// 38kHz carrier frequency for the NEC protocol
const int khz = 38;
// pins are row 1-4 and then column 1-4 from left to right
// if the keypad is hold upwards.
byte rowPins[ROWS] = {20, 19, 18, 17};
byte colPins[COLS] = {1, 2, 3, 4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
IRsend irsend;
void setup() {}
const unsigned int channel0[][21] = {
{900,2300, 800,250, 800,250, 800,300, 750,250, 800,250, 800,300, 700,350, 650,400, 650,400, 650},
{650,2550, 600,950, 600,450, 600,450, 600,500, 1050,1000, 600,450, 600,500, 550,500, 550},
{700,2500, 600,450, 600,450, 600,500, 550,500, 550,450, 600,450, 600,500, 550,500, 550,500, 550}
};
const unsigned int channel1[][21] = {
{800,2300, 900,200, 850,200, 800,250, 800,250, 800,300, 750,250, 700,350, 700,350, 700,400, 650},
{650,2500, 650,400, 650,950, 600,450, 600,450, 1100,1000, 600,450, 600,450, 600,450, 600},
{600,2550, 650,400, 600,450, 600,450, 600,450, 600,450, 600,450, 600,450, 600,450, 600,450, 650}
};
const unsigned int channel2[][21] = {
{850,2350, 800,250, 800,200, 850,250, 800,250, 800,250, 700,350, 700,350, 700,400, 650,400, 650},
{600,2550, 650,900, 1150,1000, 600,450, 1100,1000, 600,450, 550,500, 550,500, 600},
{650,2500, 650,450, 600,450, 600,400, 650,400, 650,450, 600,450, 550,500, 600,450, 600,450, 600}
};
const unsigned int channel3[][21] = {
{850,2300, 850,200, 850,200, 850,200, 850,250, 750,300, 750,300, 650,400, 650,400, 650,400, 650},
{650,2500, 650,400, 650,400, 650,950, 600,450, 1100,1050, 550,500, 550,500, 550,450, 600},
{600,2600, 550,450, 600,450, 650,400, 650,450, 550,500, 550,500, 600,450, 600,450, 600,450, 600},
};
const unsigned int channel4[][21] = {
{850,2350, 850,200, 850,200, 850,200, 850,200, 800,250, 700,400, 650,400, 650,400, 650,350, 700},
{650,2500, 650,950, 600,450, 1100,1000, 1100,1000, 600,450, 600,450, 600,500, 550},
{600,2550, 600,450, 600,450, 600,450, 600,450, 600,450, 600,450, 600,500, 550,500, 550,450, 600},
};
const unsigned int channel5[][21] = {
{900,2300, 850,200, 800,300, 750,300, 750,250, 800,300, 750,300, 700,350, 650,400, 650,400, 650},
{650,2500, 650,450, 600,950, 1150,1000, 1050,1000, 600,500, 550,500, 550,500, 550},
{650,2500, 700,350, 650,450, 550,500, 550,500, 550,500, 600,450, 600,450, 600,450, 550,500, 550}
};
const unsigned int channel6[][21] = {
{800,2350, 850,200, 850,200, 850,200, 850,200, 800,300, 750,300, 650,400, 650,400, 650,400, 650},
{650,2500, 650,950, 1150,400, 600,1000, 1100,1000, 600,450, 600,500, 550,500, 550},
{650,2500, 600,450, 600,450, 600,450, 600,450, 600,450, 600,500, 550,500, 550,500, 550,500, 550}
};
const unsigned int channel7[][21] = {
{850,2350, 850,200, 800,250, 800,250, 800,250, 800,250, 800,300, 650,400, 650,400, 650,400, 650},
{650,2500, 650,400, 650,450, 600,450, 550,1000, 1100,1000, 600,500, 550,500, 550,500, 550},
{650,2550, 600,450, 600,450, 600,450, 600,450, 600,450, 600,450, 600,500, 550,500, 550,500, 550}
};
const unsigned int channel8[][21] = {
{850,2300, 850,200, 850,200, 800,250, 800,300, 750,300, 750,250, 700,400, 700,350, 700,350, 650},
{650,2500, 650,950, 650,400, 650,400, 1150,450, 600,1000, 550,500, 550,450, 600,500, 600},
{600,2550, 600,450, 600,450, 600,450, 600,450, 600,500, 550,500, 550,450, 600,450, 600,500, 600}
};
const unsigned int channel9[][21] = {
{850,2300, 850,200, 850,200, 800,250, 800,300, 750,300, 750,250, 700,400, 650,400, 650,400, 650},
{650,2500, 650,400, 650,950, 600,450, 1100,500, 600,1000, 550,450, 600,450, 600,450, 600},
{650,2500, 650,400, 550,550, 550,500, 500,550, 550,500, 550,500, 550,500, 550,500, 600,450, 550},
};
const unsigned int sw_blue[][21] = {
{850,2300, 850,200, 850,200, 900,200, 800,250, 750,300, 750,300, 700,350, 700,350, 700,350, 700},
{600,2500, 700,900, 1150,450, 600,450, 600,950, 1150,1000, 550,500, 600,450, 600},
};
const unsigned int sw_red[][21] = {
{900,2300, 850,200, 850,250, 750,300, 750,250, 850,250, 750,300, 700,350, 650,400, 650,400, 650},
{650,2550, 600,950, 1100,1000, 1150,450, 550,500, 550,1050, 550,500, 500,550, 550},
};
const unsigned int sw_yellow[][21] = {
{850,2300, 850,200, 900,200, 800,250, 800,250, 750,300, 750,300, 700,350, 700,350, 700,350, 700},
{650,2550, 650,400, 600,450, 600,950, 1150,450, 600,450, 600,1000, 600,450, 600,450, 600},
};
const unsigned int sw_green[][21] = {
{900,2300, 850,200, 800,250, 800,250, 800,300, 750,250, 800,250, 700,400, 650,400, 650,400, 650},
{650,2500, 650,950, 1150,450, 550,450, 600,450, 650,450, 600,950, 600,450, 600,450, 600},
};
const unsigned int teletext[][21] = {
{850,2300, 850,200, 850,200, 850,250, 750,300, 750,300, 750,300, 650,400, 700,350, 700,350, 700},
{650,2500, 700,900, 600,450, 600,450, 650,400, 1150,450, 600,1000, 550,500, 600,450, 550},
};
const unsigned int sw_input_next[][21] = {
{850,2300, 850,200, 850,200, 850,250, 800,250, 750,300, 750,300, 700,350, 700,350, 700,350, 650},
{650,2500, 650,950, 650,400, 1100,1000, 600,500, 550,500, 550,450, 600,450, 650,400, 650},
};
const unsigned int sw_off[][21] = {
{850,2300, 850,250, 800,250, 750,300, 750,300, 700,350, 700,350, 700,350, 700,350, 650,400, 650},
{650,2550, 600,950, 1150,1000, 550,500, 550,500, 550,450, 600,500, 600,450, 600,450, 550},
};
void sendraw(const unsigned int data[][21], byte x) {
irsend.sendRaw(data[x], sizeof(data[x]) / sizeof(data[x][0]), khz);
delay(50);
}
void sendcode(char code) {
Serial.print("Sending codes [");
Serial.print(code);
Serial.println("]");
switch (code) {
case '0':
for (int i = 0; i < 3; i++) {
sendraw(channel0, i);
}
break;
case '1':
for (int i = 0; i < 3; i++) {
sendraw(channel1, i);
}
break;
case '2':
sendraw(channel2, 0);
for (int i = 0; i < 3; i++) {
sendraw(channel2, 1);
}
sendraw(channel2, 2);
break;
case '3':
for (int i = 0; i < 3; i++) {
sendraw(channel3, i);
}
break;
case '4':
sendraw(channel4, 0);
for (int i = 0; i < 3; i++) {
sendraw(channel4, 1);
}
sendraw(channel4, 2);
break;
case '5':
for (int i = 0; i < 3; i++) {
sendraw(channel5, i);
}
break;
case '6':
for (int i = 0; i < 3; i++) {
sendraw(channel6, i);
}
break;
case '7':
for (int i = 0; i < 3; i++) {
sendraw(channel7, i);
}
break;
case '8':
sendraw(channel8, 0);
for (int i = 0; i < 2; i++) {
sendraw(channel8, 1);
}
sendraw(channel8, 2);
break;
case '9':
for (int i = 0; i < 3; i++) {
sendraw(channel9, i);
}
break;
case '#':
sendraw(sw_off, 0);
for (int i = 0; i < 3; i++) {
sendraw(sw_off, 1);
}
break;
case '*':
sendraw(sw_input_next, 0);
for (int i = 0; i < 2; i++) {
sendraw(sw_input_next, 1);
}
for (int i = 0; i < 2; i++) {
sendraw(teletext, i);
}
break;
case 'A':
for (int i = 0; i < 2; i++) {
sendraw(sw_red, i);
}
break;
case 'B':
for (int i = 0; i < 2; i++) {
sendraw(sw_green, i);
}
break;
case 'C':
for (int i = 0; i < 2; i++) {
sendraw(sw_yellow, i);
}
break;
case 'D':
for (int i = 0; i < 2; i++) {
sendraw(sw_blue, i);
}
break;
};
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
Serial.print("Sending code: ");
Serial.println(customKey);
sendcode(customKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment