#include "DPir.h"
#define IRpin 4
DPir dpir(IRpin,10000); // 10000 us je minimalni razmak između dva IR koda
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13, OUTPUT);
Serial.println("Booting");
}
// 0x23 -> 23
uint8_t BCD2DEC(uint8_t bcd)
{
uint8_t dec=0;
dec = (bcd>>4)*10 + (bcd&0x0F);
return dec;
}
// 23 -> 0x23
uint8_t DEC2BCD(uint8_t dec)
{
uint8_t bcd=0;
bcd = ((dec/10)<<4) + dec%10;
return bcd;
}
// 13h18m23s
uint16_t nTmp=0;
int checkSerial()
{
while(Serial.available())
{
char c=Serial.read();
if(c>='0' && c<='9') {
nTmp = nTmp*10 + (c-'0');
}
if(c=='h') {
Serial.print("Upisi u sate:");
Serial.println(nTmp);
nTmp=0;
}
if(c=='m') {
Serial.print("Upisi u minute:");
Serial.println(nTmp);
nTmp=0;
}
if(c=='s') {
Serial.print("Upisi u sekunde:");
Serial.println(nTmp);
nTmp=0;
}
}
return 3;
}
int checkSerial2()
{
String s = Serial.readString();
return s.length();
}
int k=0;
int tt=0;
uint32_t t1=0,t2=0;
void loop() {
// put your main code here, to run repeatedly:
//checkSerial();
t1=millis();
tt=checkSerial();
t2=millis();
//Serial.println("-----------------");
//Serial.println(t2-t1);
//Serial.println(tt);
//Serial.println(BCD2DEC(0x59));
//Serial.println(DEC2BCD(23),HEX);
if(dpir.available()!=0)
{
uint32_t IRcode = dpir.getCode();
if(IRcode == 0x94155415) digitalWrite(13, !digitalRead(13));
else Serial.println(IRcode,HEX);
}
}