#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <Keypad.h>
#define PIN_RECEIVER 25
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
long first = 0;
long second = 0;
double total = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {14,15,16,17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {18,19,20,21}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
lcd.begin(16,2); // start lcd
lcd.setCursor(0,0);
lcd.print(" Bonjour ");
lcd.setCursor(0,1);
lcd.print("Le Programmeur");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Entre votre code");
lcd.setCursor(0,1);
receiver.enableIRIn(); //DEMARRAGE DE receiver
}
void loop() {
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
customKey = customKeypad.getKey();
switch(customKey)
{
case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
lcd.setCursor(0,1);
first = first * 10 + (customKey - '0');
lcd.print(first);
break;
case 'C':
lcd.clear();
first =0;
break;
case 'A':
lcd.clear();
break;
case 'B':
lcd.clear();
break;
case 'D':
lcd.print("D");
break;
case '*':
lcd.print("*");
break;
case '#':
lcd.print("#");
break;
}
}
void lcdPrint(char* text)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(text);
lcd.print(receiver.decodedIRData.command);
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
lcdPrint("POWER");
break;
case 226:
lcdPrint("MENU");
break;
case 34:
lcdPrint("TEST");
break;
case 2:
lcdPrint("PLUS");
break;
case 194:
lcdPrint("BACK");
break;
case 224:
lcdPrint("PREV.");
break;
case 168:
lcdPrint("PLAY");
break;
case 144:
lcdPrint("NEXT");
break;
case 104:
lcdPrint("num: 0");
break;
case 152:
lcdPrint("MINUS");
break;
case 176:
lcdPrint("key: C");
break;
case 48:
lcdPrint("num: 1");
break;
case 24:
lcdPrint("num: 2");
break;
case 122:
lcdPrint("num: 3");
break;
case 16:
lcdPrint("num: 4");
break;
case 56:
lcdPrint("num: 5");
break;
case 90:
lcdPrint("num: 6");
break;
case 66:
lcdPrint("num: 7");
break;
case 74:
lcdPrint("num: 8");
break;
case 82:
lcdPrint("num: 9");
break;
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}