void switch2transmit() { disableRx = true; // ------------------ GO TO TRANSMIT STATE ------------------------- digitalWrite(txEnablePin, HIGH); delayMicroseconds( 400 ); // ------------------ GO TO TRANSMIT STATE ------------------------- } void switch2receive() { // ------------------ GO TO RECEIVE STATE ------------------------- // From Transmission Mode to Receiver Mode follow the procedure: // Drive down pin 5 (RX/TX), after 40us drive down pin 6 (ENABLE) 20us long. //After 200 us the device is ready for reception. digitalWrite(txEnablePin, LOW); delayMicroseconds( 40 ); digitalWrite(enablePin, LOW); delayMicroseconds( 20 ); digitalWrite(enablePin, HIGH); delayMicroseconds( 200 ); // ------------------ GO TO RECEIVE STATE ------------------------- disableRx = false; } void sendPulse(int high, int low) { digitalWrite(txPin, HIGH); delayMicroseconds( high ); digitalWrite(txPin, LOW); delayMicroseconds( low ); } // Nexa : http://elektronikforumet.com/wiki/index.php/RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande // "1" = 295 µs hög och 170 µs låg // "0" = 295 µs hög och 920 µs låg // // Etta skickas som 10 och Nolla som 01 // // Dessa siffror från web-sidan stämmer inte med den Nexa-kontroll som jag har. // Jag har rättat dessa med siffror från verkligheten. Finns i define's nedan. // // // Timing for NEXA Remote controls #define HIGH_PULSE 240 #define LOW_PULSE_0 300 #define LOW_PULSE_1 1300 #define SYNC_PULSE 2700 #define STOP_PULSE 10000 void send1() { sendPulse( HIGH_PULSE, LOW_PULSE_1); // 1 sendPulse( HIGH_PULSE, LOW_PULSE_0 ); // 0 } void send0() { sendPulse( HIGH_PULSE, LOW_PULSE_0 ); // 0 sendPulse( HIGH_PULSE, LOW_PULSE_1); // 1 } void sendSync() { sendPulse( HIGH_PULSE, SYNC_PULSE ); } void sendStop() { sendPulse( HIGH_PULSE, STOP_PULSE ); } void sendNexaCode(unsigned long int txCode) { unsigned long int code=0; unsigned long int orig_code=txCode; int i; int loop; if( 1 == 1 ) { // Turn off interrupts from the timer TIMSK1 = 0; switch2transmit(); for( loop=6; loop>0; loop--) { code = orig_code; sendSync(); for(i=0; i < 32; i++) { if( code & 0x80000000 ) { send1(); } else { send0(); } code = (code << 1); } sendStop(); } switch2receive(); // Enable interrupts again TIMSK1 |= (1 << OCIE1A); } }