// URFUKED Pwner interface and transmitter code. // by Monta Elkins // monta.defcon@geekslunch.com // // http://www.hackerwarrior/urfuked // // Based on a Teensy 2.0 and a WRL-08945 RF transmitter int debug=0; int read_button; int debounce_time=25; // button press debounce int command_byte=0; // This bit represents which bit will be set or unset by the current button press // it starts with bit 3 and progresses across the display to bit 0, the wraps // back to bit 3 int bit=3; // Transmitter setup // This line defines a "Uart" object to access the serial port // The serial port (TX - pin D3) is connected to the transmitter HardwareSerial Uart = HardwareSerial(); int carrier_byte=170; // "AA" hex // command sequcence number is used to allow a command to be transmitted // multiple times (for redundancy), but only executed once int command_seq_no=2; int checksum=0; void setup() { // setup 3 switches (active low) pinMode(PIN_F0, INPUT); digitalWrite(PIN_F0, HIGH); // set pullup pinMode(PIN_F1, INPUT); digitalWrite(PIN_F1, HIGH); // set pullup pinMode(PIN_F4, INPUT); digitalWrite(PIN_F4, HIGH); // set pullup // Setup 4 leds for Output pinMode(PIN_B0, OUTPUT); pinMode(PIN_B1, OUTPUT); pinMode(PIN_B2, OUTPUT); pinMode(PIN_B3, OUTPUT); // use pin 11 as "power-on light" - turn it on // (this is the "built in" Teensy 2.0 led) digitalWrite(11,HIGH); // blink lights at power on // This cycles through the lights as a "system check" digitalWrite(PIN_B0, HIGH); delay(100); digitalWrite(PIN_B1, HIGH); delay(100); digitalWrite(PIN_B2, HIGH); delay(100); digitalWrite(PIN_B3, HIGH); delay(100); //now turn them off digitalWrite(PIN_B0, LOW); digitalWrite(PIN_B1, LOW); digitalWrite(PIN_B2, LOW); digitalWrite(PIN_B3, LOW); // Transmitter Setup Uart.begin(1200); // delay for debug printing if (debug> 0) {delay (10000);} if (debug>2){Keyboard.print(" Transmitter ready v.02 " );} } void debounce(int PIN){ // pretty simple minded debounce routine- but effective delay(debounce_time); // wait for switch to settle low while (digitalRead(PIN)==LOW) { // wait for release } delay(debounce_time); // Now that button is release wait for debounce time } void loop() { //=================================== // User Interface Code //==================================== // /////////////////////////////// // SWITCH "0" /////////////////////////////// if (digitalRead(PIN_F4)==LOW) { // 0 button pressed debounce(PIN_F4); // blink LED in case all 0's bitSet(command_byte,bit); write_leds(command_byte); delay(50); bitClear(command_byte,bit--); if (debug>2) {Keyboard.println("0");} write_leds(command_byte); } /////////////////////////////// // SWITCH "1" /////////////////////////////// if (digitalRead(PIN_F1)==LOW) { // 1 button pressed debounce(PIN_F1); // Blink LED in case all 1's bitClear(command_byte,bit); write_leds(command_byte); delay(50); bitSet(command_byte,bit--); if (debug>2){Keyboard.println("1");} write_leds(command_byte); } if (bit<0) { // keyboard input is from high bit to low // did bit number wrap to negative? then restart bit=3; } /////////////////////////////// // SWITCH "Send Command" /////////////////////////////// if (digitalRead(PIN_F0)==LOW) { // "Send Command" button pressed debounce(PIN_F0); if (debug>0) { Keyboard.print("Command Sent:"); Keyboard.println(command_byte); } // Call send command here transmit_command(); delay(50); // or send_buttone debounce issue? command_byte=0; // clear display on return bit=3; } // update display write_leds(command_byte); } // Display the current command_byte on the LED display int write_leds(int command_byte){ digitalWrite(PIN_B0, bitRead(command_byte,0)); digitalWrite(PIN_B1, bitRead(command_byte,1)); digitalWrite(PIN_B2, bitRead(command_byte,2)); digitalWrite(PIN_B3, bitRead(command_byte,3)); } //=================================== // Transmitter Code //==================================== // Used to send the command_byte // to the reciever void transmit_command() { // Send each frame 10 times for redundancy (against RF noise) int i=0; while (i++<9){ ///////////////////////// // Send a Frame //////////////////////// // Each frame has 10 bytes of Carrier int j=0; while (j++<9) { Uart.write(carrier_byte); //delay (10); } // Send Command Sequence Number Uart.write(command_seq_no); // Send Command Byte Uart.write(command_byte); // Send Check sum checksum=command_byte+command_seq_no; Uart.write(checksum); } //------------------------- // Done sending this frame //-------------------------- // Do a little house keeping and send it again... command_seq_no++; // increment command sequence number // if command sequnce number > 126, wrap it around to 1 if (command_seq_no>126) { command_seq_no=1;} if (debug>1) {Keyboard.print("Sent Command Byte ");} }