please check my code in this simulation site..
this IR receiver always returns 1, so I inverted signal 1 and 0 on this picture
and if signal 0 is shorter then 1ms (562.5us) read as 0, and longer then 1ms(1.6875us) read as 1.
I think its working, initial state displaying well , 9 ms of 0 signal, 4.5ms of 1signal
, but command and inverted command, address and inverted address is not matching, and also command is changing everytime when press the same button
I think problem is on code.. but I can't find what is problem on code..
can you check code and help me..
here is my full code::
// C++ code
const int IR_PIN_NUMBER = 8;
struct TimelinePackage{
int duration_millis;
int readed;
TimelinePackage(int dur, int read) {
duration_millis=dur;
readed=read;
}
void to_string(){
Serial.println(String("duration: ") + duration_millis + String("/readed: ") + readed);
}
};
TimelinePackage** ReadAllTimelines(int PIN_NUMBER, int bytes_to_read);
void setup() {
pinMode(IR_PIN_NUMBER, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(IR_PIN_NUMBER) != 1) {
TimelinePackage** packages= ReadAllTimelines(IR_PIN_NUMBER, 67);
//I manually calculated total bytes ((8(address/command size) * 4) * 2(0 and 1)) + 2(initial states) + 1(final byte)
int total_writed=0;
for(int i=0; i<67; i++){
if(packages[i]-> readed==1){
if(packages[i]-> duration_millis==0){
Serial.print(0);
}else{
Serial.print(1);
}
total_writed++;
if(total_writed==1){
Serial.print('\t');
}
if(total_writed>=8 && total_writed % 8 == 0){
Serial.print('\t');
}
}
}
Serial.print('\n');
for(int i=0; i<67; i++){
packages[i]->to_string();
delete packages[i];
}
delete packages;
Serial.print('\n');
}
}
TimelinePackage** ReadAllTimelines(int PIN_NUMBER, int bytes_to_read) {
TimelinePackage** packages = new TimelinePackage*[bytes_to_read];
for(int i = 0; i < bytes_to_read; i++) {
int mills_1 = millis();
int readed = digitalRead(PIN_NUMBER);
while(digitalRead(PIN_NUMBER) == readed) {};
int duration = millis() - mills_1;
packages[i] = new TimelinePackage(duration, readed);
}
return packages;
}