TIMSK1 = 0; // disable timer interrupt
}
+union {
+ byte uint8[4];
+ uint32_t uint32;
+} rf433_data;
+byte rf433_hi_cnt=0;
+byte rf433_lo_cnt=0;
+byte last_sample=0;
+int valid=0;
ISR(TIMER1_COMPA_vect)
{
- digitalRead(RF433_PIN);
+ byte sample = digitalRead(RF433_PIN);
+ if (last_sample!=sample && sample==HIGH)
+ {
+ if ( rf433_lo_cnt > 2 && rf433_lo_cnt<6 && rf433_hi_cnt>10 && rf433_hi_cnt < 14)
+ {
+ rf433_data.uint32<<=1;
+ rf433_data.uint32|=1;
+ valid++;
+ } else if (rf433_hi_cnt > 2 && rf433_hi_cnt<6 && rf433_lo_cnt>10 && rf433_lo_cnt < 14) {
+ rf433_data.uint32<<=1;
+ valid++;
+ } else if (rf433_hi_cnt > 2 && rf433_hi_cnt<6 && rf433_lo_cnt>120 && rf433_lo_cnt < 128 && valid >=24) {
+ //rf433_data.uint8[3]=0;
+ //Serial.print(rf433_data.uint32);
+ Serial.print(rf433_data.uint8[0],BYTE);
+ Serial.print(rf433_data.uint8[1],BYTE);
+ Serial.print(rf433_data.uint8[2],BYTE);
+ //Serial.print(rf433_data.uint8[3],BYTE);
+ } else {
+ valid=0;
+ rf433_data.uint32=0;
+ }
+ rf433_hi_cnt=0;
+ rf433_lo_cnt=0;
+ }
+ if (sample == HIGH)
+ rf433_hi_cnt++;
+ else
+ rf433_lo_cnt++;
+ last_sample=sample;
}
//unsigned long wm_start_[3]={0,0,0};
digitalWrite(RF433_PIN, LOW); // turn of pullup resistors
Serial.begin(57600);
+// Serial.println("starting timer");
start_timer();
}