Hello, i'm working on an IR Project using keypad as an input and serial monitor as an output. I also using Pulse distance Coding and NEC remote protocol.
This is my tx code:
#include <Keypad.h>
String kodebithuruf[]=
{"01100001","01100010","01100011","01100100","01100101",
"01100110","01100111","01101000","01101001","01101010",
"01101011","01101100","01101101","01101110","01101111",
"01110000","01110001","01110010","01110011","01110100",
"01110101","01110110","01110111","01111000","01111001",
"01111010","00100000",
"00110000","00110001","00110010","00110011","00110100",
"00110101","00110110","00110111","00111000","00111001",
"00101110","00101100","00111010"};
char data[50];
int k=0;
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','^'},
{'4','5','6','/'},
{'7','8','9','
And this is my Rx code:
volatile int durasi;
volatile int prev_time;
volatile int data_simpan[255];
int x=0;
byte tambah;
void setup() {
Serial.begin(250000);
Serial.println(F("Ready to receive IR signals"));
attachInterrupt(1, jatuh, RISING);
}
void loop() {
}
void jatuh() {
detachInterrupt(1);
prev_time=micros();
attachInterrupt(1,naik,FALLING);
}
void naik(){
detachInterrupt(1);
durasi=micros()-prev_time;
data_simpan[x]=durasi;
baca(data_simpan[x]);
x++;
attachInterrupt(1, jatuh, RISING);
}
byte lock=0;
int ya=0;
void baca(int sementara){
if (ya!=9){
if ((sementara < 5000)&&(sementara > 4000)){
ya=1;
tambah==1;
lock==0;
//"header"
} else if ((sementara < 2000)&&(sementara > 1500)){
lock==tambah+lock;
tambah=tambah*2;
ya++;
//"1";
} else if ((sementara < 800)&&(sementara > 300)){
tambah=tambah*2;
ya++;
//"0";
}
}else if (ya==9){
Serial.write(lock);
tambah=1;
lock==0;
ya=1;
}else{
Serial.println("Error bit");
}
}
I succeed when i read binary data and if i only send 1 character and reset it before send any other data, but if i send more than 1, strange character always showed up.
This is my first post, so sorry if i mistaken anything. I really want to graduate this year, so i really appreciate any kind of help, thanks!},
{'<','0','>','@'}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {11, 10, 9, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(1200);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
if (key!='
And this is my Rx code:
§DISCOURSE_HOISTED_CODE_1§
I succeed when i read binary data and if i only send 1 character and reset it before send any other data, but if i send more than 1, strange character always showed up.
This is my first post, so sorry if i mistaken anything. I really want to graduate this year, so i really appreciate any kind of help, thanks!){
data[k]=key;
k++;
}else if(key='
And this is my Rx code:
§_DISCOURSE_HOISTED_CODE_1_§
I succeed when i read binary data and if i only send 1 character and reset it before send any other data, but if i send more than 1, strange character always showed up.
This is my first post, so sorry if i mistaken anything. I really want to graduate this year, so i really appreciate any kind of help, thanks!){
k++;
data[k]='!';
header();
hasil();
}
}
}
void header() {
tone(3,38000);
delayMicroseconds(4250);
noTone(3);
header_mark();
}
void header_mark() {
noTone(3);
digitalWrite(3,HIGH);
delayMicroseconds(4500);
Serial.println("header");
}
void logika0(){
tone(3,38000);
delayMicroseconds(260);
noTone(3);
digitalWrite(3,HIGH);
delayMicroseconds(520);
Serial.print('0');
return;
}
void logika1(){
tone(3,38000);
delayMicroseconds(260);
noTone(3);
digitalWrite(3,HIGH);
delayMicroseconds(1670);
Serial.print('1');
return;
}
void kirimhuruf(int posisi){
String simbol = kodebithuruf[posisi];
for (int i=simbol.length();i>-1;i--;){
if (simbol[i]=='1'){
logika1();
}else{
logika0();
}
}
}
void hasil() {
int karakter;
int p=0,s=0;
while (data[p]!='!'){
p++;
}
for (int k=0;k<p;k++){
karakter = data[k];
Serial.print(data[k]);
if ((karakter>='a')&&(karakter<='z'))
kirimhuruf(karakter-'a');
else
if ((karakter>='A')&&(karakter<='Z'))
kirimhuruf(karakter-'A');
else
if (karakter==' ')
kirimhuruf(26);
else
if ((karakter>='0')&&(karakter<='9'))
kirimhuruf(karakter-'0'+27);
else
if (karakter=='.')
kirimhuruf(37);
else
if (karakter==',')
kirimhuruf(38);
else
if (karakter==':')
kirimhuruf(39);
}
}
And this is my Rx code:
§DISCOURSE_HOISTED_CODE_1§
I succeed when i read binary data and if i only send 1 character and reset it before send any other data, but if i send more than 1, strange character always showed up.
This is my first post, so sorry if i mistaken anything. I really want to graduate this year, so i really appreciate any kind of help, thanks!