아두이노 우노와 만능 멤브레인 키패드 3x4, 그리고 IR 송수신 모듈을 가지고 시계용 IR 리모콘을 한번 만들어 보았다.
제일 어려운 것이 리모콘의 송신 신호를 알아내는 것이었다. 리모콘이 있다면, 신호를 송신해보고 그 신호를 복제하는 방법으로 하면 쉽게 갈 수 있지만, 리모콘이 없으므로 모든 코드 신호를 다 보내보면서 시계쪽의 변화를 봐야했기에 완전 쌩노가다였다.
아두이노 IDE에 keypad 라이브러리와 IRremote 라이브러리를 설치해서 아래 코드를 아두이노 우노에 업로드하면 된다.
물론 키패드와 송수신 모듈을 아두이노와 연결해야 되는데, 연결방법은 인터넷에 다 있다. (검색하면 된다.)
그냥 길게 누름의 신호를 별도의 키 하나에 할당해서 간단하게 구현하였다.
LED 벽시계의 키는 8개뿐이지만, 길게 누름이 3개 할당되어 있어서, 키를 11개만 쓰면 되기 때문에.
// Code for IR controller of Mooas LCD Digital Wall Clock
// coded by HooK7346
// 2023. 3. 8.
/*
* Key # : LED On/Off
* Key * : Change Display
* Key 1 : Brightness Auto On/Off
* Key 2 : Time dot Fade In/Out setting
* Key 3 : Alarm On/Off
* Key 4 : Settings Menu
* Key 5 : OK, Next
* Key 7 : Alarm Time Check
* Key 8 : Alarm Setting
* Key 6 : Up
* Key 9 : Down
*/
#include <Arduino.h>
#define DISABLE_CODE_FOR_RECEIVER // Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used.
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
#include <IRremote.hpp>
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
uint8_t sCmd_LED_On_Off = 0x1C;
uint8_t sCmd_Change_Display = 0x40;
uint8_t sCmd_Bright_Auto_On_Off = 0x08;
uint8_t sCmd_Alarm_On_Off = 0x44;
uint8_t sCmd_Setting = 0x5E;
uint8_t sCmd_Alarm_Setting = 0x4A;
uint8_t sCmd_Up = 0x18;
uint8_t sCmd_Down = 0x52;
uint8_t sRepeats_short = 0;
uint8_t sRepeats_long = 30;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin and disable feedback LED at default feedback LED pin
Serial.print(F("Send IR signals at pin "));
Serial.println(IR_SEND_PIN);
}
void loop() {
char key = keypad.getKey();
switch (key) {
case '#':
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_LED_On_Off, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_LED_On_Off, sRepeats_short);
break;
case '*': // Change Display button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Change_Display, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Change_Display, sRepeats_short);
break;
case '1': // Brightness Auto On/Off button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Bright_Auto_On_Off, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Bright_Auto_On_Off, sRepeats_short);
break;
case '2': // Time dot Fade In/Out setting button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Bright_Auto_On_Off, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_long);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Bright_Auto_On_Off, sRepeats_long);
break;
case '3': // Alarm On/Off button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Alarm_On_Off, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Alarm_On_Off, sRepeats_short);
break;
case '4': // Settings Menu button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Setting, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_long);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Setting, sRepeats_long);
break;
case '5': // OK, Next button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Setting, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Setting, sRepeats_short);
break;
case '7': // Alarm Time Check button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Alarm_Setting, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Alarm_Setting, sRepeats_short);
break;
case '8': // Alarm Settings button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Alarm_Setting, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_long);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Alarm_Setting, sRepeats_long);
break;
case '6': // Up button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Up, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Up, sRepeats_short);
break;
case '9': // Down button
/*
* Print current send values
*/
//Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCmd_Down, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats_short);
Serial.println();
//Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
IrSender.sendNEC(0x00, sCmd_Down, sRepeats_short);
break;
}
}