// PT2272_SIM.ino // SC2272/PT2272 Emulation Test // By Thomas Olson // Rev. teo20130130.02 // For Arduino /* Grab and measure widths of the next 120 pos/neg pulses. Get timestamps and polarity of all pulse edges for SAMPLES. Analyze the timestamps to obtain the four types of pulses... shortlow, longlow, shorthigh, longhigh. Analyze the combinations to determine 22x2 tristate values... 1, 0, or F, or S(ync) First attempt assumes 4.7Mohm/820Kohm set */ /* TODO: - Determine osc times for other two popular resistor settings. 1.2M/220K and 1.5M/270K - What other things are running at 433MHz with different protocols */ #define FoscCshort 500 // nominal short pulse uS #define FoscClong 1500 // nominal long pulse uS #define FoscTol 200 // tolerance uS #define SHORTMAX FoscCshort + FoscTol #define SHORTMIN FoscCshort - FoscTol #define LONGMAX FoscClong + FoscTol #define LONGMIN FoscClong - FoscTol // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; long starttime, stoptime; int rfdata_in = 3; //PD3 (INT1) #define SAMPLES 120 unsigned long edges[SAMPLES]; // store time in microseconds unsigned long pulses[SAMPLES]; // store pulses in microseconds <65535uS unsigned char polarity[SAMPLES]; char pulsePair[SAMPLES]; char addressData[SAMPLES]; void setup() { pinMode(led, OUTPUT); Serial.begin(115200); pinMode(rfdata_in,INPUT); while(!Serial){;} } void loop() { for(int x;xHIGH"); // low to high edge detected edges[x] = micros(); polarity[x] = 1; // Serial.println("0>1 "); while((PIND & (1<LOW"); // high to low edge detected edges[x+1] = micros(); polarity[x+1] = 0; // Serial.println("1>0 "); } digitalWrite(led, HIGH); // LED ON after edges samples detected for(int x=1; x pulses[x+1]){ // Hi longer Lo might be ONE if(pulses[x]>LONGMIN && pulses[x]SHORTMIN && pulses[x+1]SHORTMIN && pulses[x]LONGMIN && pulses[x+1]14400 && pulses[x+1]<<17600){ //Sync valid // valid interim digit S(ync) pulsePair[x/2]='S'; } } } // Analyse to get actual security CODES int x=0; int y=0; // Find the first S while(pulsePair[x] != 'S' && x