Xbox 360 RF module + Arduino

I was going to make a huge write-up on this, but I can’t be bothered right now. I’ll probably do something about it later. Until then, have an Arduino sketch. If you don’t know what you’re doing with it then chances are you don’t have an Arduino, in which case the file is useless to you.

The sketch:

/* Arduino code to communicate with xbox 360 RF module.
Original work by (yaywoop) / additional ideas from Alexander Martinez - modified by dilandou (www.dilandou.com, www.diru.org/wordpress)
First sends LED initialisation code followed by LED startup animation code, then sleeps until a button press for sync command.
RF module must be powered with 3.3V, two diodes in series with USB 5v will do. Connect the USB wires to a host computer, and the data and serial wires to Arduino.
of course, make sure to have a common ground */

#include <avr/sleep.h>

#define sync_pin 2 //power button repurposed for sync button (pin 5 on the module)
#define data_pin 3 //data line (pin 6 on the module)
#define clock_pin 4 //clock line (pin 7 on module) 

int led_cmd[10] =  {0,0,1,0,0,0,0,1,0,0}; //Activates/initialises the LEDs, leaving the center LED lit.
int anim_cmd[10] = {0,0,1,0,0,0,0,1,0,1}; //Makes the startup animation on the ring of light.
int sync_cmd[10] = {0,0,0,0,0,0,0,1,0,0}; //Initiates the sync process.
volatile boolean sync_enable = 0;

void sendData(int cmd_do[]) {
  pinMode(data_pin, OUTPUT);
  digitalWrite(data_pin, LOW);    //start sending data.
  int prev = 1;
  for(int i = 0; i < 10; i++){

    while (prev == digitalRead(clock_pin)){} //detects change in clock
    prev = digitalRead(clock_pin);
      // should be after downward edge of clock, so send bit of data now
    digitalWrite(data_pin, cmd_do[i]);

    while (prev == digitalRead(clock_pin)){} //detects upward edge of clock
    prev = digitalRead(clock_pin);
  }
  digitalWrite(data_pin, HIGH);
  pinMode(data_pin, INPUT);
}

void initLEDs(){
	sendData(led_cmd);
	delay(50);
	sendData(anim_cmd);
	delay(50);
}

void wakeUp(){
  sync_enable = 1;
}

void sleepNow() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // set sleep mode
  sleep_enable(); //enable sleep bit
  attachInterrupt(0, wakeUp, LOW);
  sleep_mode();
  sleep_disable(); //disable sleep bit
  detachInterrupt(0); // disables interrupt 0 on pin 2
}

void setup() {
  Serial.begin(9600);
  pinMode(sync_pin, INPUT);
  digitalWrite(sync_pin,HIGH);
  pinMode(data_pin, INPUT);
  pinMode(clock_pin, INPUT);
  delay(2000);

  initLEDs();
//  sendData(sync_cmd);
}

void loop(){
  Serial.println("Sleeping.");
  sleepNow();
  delay(200);
  if(sync_enable==1) {
    Serial.println("Syncing.");
    sendData(sync_cmd);
    sync_enable = 0;
  }
}

 

xbox360_rf_plus_arduino_schematic

Advertisements

70 thoughts on “Xbox 360 RF module + Arduino

  1. iScypek

    I have ATMEGA8 uC, could you send me hex file for arduino with this uC? I triet to compile it on arduino, but i have only project file and i dont know the path of hex files.

    Reply
    1. dilandou Post author

      In the Arduino IDE, hold Shift while clicking the Upload button. This triggers verbose mode, and will show where the hex file is temporarily held. The hex files are deleted as soon as you close the IDE.

      Reply
    2. Adam W.

      Acquired a busted RROD 360 and salvaged the RF module. Luckily I was able to sync a remote before the system died altogether, but all I have right now is the RF module and the one remote… It does work, and there are no issues with the current setup. However, If I want to sync this controller to another device, and come back – OR sync other controllers as well as my primary – I’m SoL right now… I’m looking at the Arduino product page, and I’m unclear on which model I should purchase. Could I please get direction on the most bare bones of hardware that would be required to get this up and running with the ability to sync devices? Again, got the RF card working, got one controller currently synced, can not sync others. What is the quickest, easiest, most bare bones hardware requirements to be able to add sync functionality to this?

      Reply
      1. dilandou Post author

        The most barebones equipment would be a single microcontroller and a programmer for it. There are several examples in the comments here. If you don’t have a programmer then a simple option is a barebones development board such as Teensy USB ($16), PICAXE (kits around $16 also), tinyUSBboard (around $6 in parts and effort to assemble).

  2. Michael Rogers

    This controls the sync process and state of the leds. Am I correct in assuming that the state of the controller buttons are not accessible to the arduino, but over usb only?

    Reply
    1. dilandou Post author

      To be honest, I haven’t dug that far into it. I was planning on a little experimentation, but never got around to it. What I do know is that when you send certain commands to the RF unit, it will send data back over the same line. I think, however, it’s mostly things like “I have X controllers connected” or “This controller is controller X” etc. Useful for fine tuning the lights, if you wanted to be more fancy, but not much else.

      Reply
  3. Timinator01

    my controller wont sync … the module does the sync light animation and so does the controller but they wont do it at the same time. when both are syncing it automatically starts all leds flashing and then the module stops and the controller just keeps flashing instead of a player # light turning on like with a real xbox. any ideas on how to fix this? the xbox rf module is x802779-010 rev:A-1-1 and the controllers are x809478-001 and x817145-006 (i think these are the model numbers)

    Reply
    1. dilandou Post author

      Sounds like a bit of a dumb question, and I apologise for asking it, but when you say the sync animation, you mean after you’ve pressed the center button and not the animation when it’s first powered on, correct?

      Also, the module itself won’t have an LED lit to show it has a controller connected. Unfortunately it would require figuring out the data sequence it replies with to say what number controller is connected, then telling it to light whichever LED. Extra effort for an entirely cosmetic feature. 😛

      It would seem that there’s a rev B hardware now with different pinouts. It’s easily identified with the RF02 moniker. The main differences seem to be DATA on pin 7, and CLK on pin 9 (at 130hz).

      Reply
    1. dilandou Post author

      There are people asking a similar thing here: http://forums.xbox-experts.com/viewtopic.php?t=4029&p=26982

      Personally I’ve not gone that deep into it as I’m not confident enough to start reverse engineering protocols. From the seems of it, though, the general idea is that you could either set a uC up as a USB host and decode whatever data is sent over USB, or directly hook into the logic going between the RF chip and the USB chip and use the raw data from there. If you have a logic analyser or oscilloscope give it a try. I’d be curious to know the results myself.

      Reply
  4. Chris

    Hi there, I was wondering if I could get a quick schematic that corresponds with the code posted here. I have only worked with Motorola chips and assembly in the past and don’t have much experience with the arduino, it’s libraries, and much c.

    I’ve gone ahead and made sense of the code (save a few lines) and I would like to confirm a few speculations based on the arduino’s pinout and a schematic.

    Sorry for the trouble.

    Reply
    1. dilandou Post author

      I’ve added a schematic to the bottom of the post. It’s pretty simple so far as things go. If you’re paranoid about the logic being above the 3.3V supply for the board, you can either ignore it, or stick some voltage dividers in there, but considering the logic only happens for -very- short times, it’s mostly unnecessary.

      If you wanted a more permanent and less wire hogging solution, you could always power the Arduino from the usb supply powering the RF module. Essentially the only need for the Arduino to have a USB connection is for the serial debugging (which you can safely remove from the code).

      Personally I’ve moved the whole thing over to an ATTINY45 soldered directly onto the board. Using an Arduino permanently is a wee bit overkill, afterall.

      Reply
      1. Kevin Groce

        Can you give me a bit more details on how to hook the TINY up? In your other post they used the test points on the module. I would like to get a good idea on how to use it. Also the TINY code you use was the file he posted?

      2. dilandou Post author

        I used a quick and dirty port of my Arduino code for the ATTINY45, nothing made public yet. I might clean it up at some point. As for my wiring, I used near on exactly the same wiring as with the Arduino, only to pins 5, 6, and 7 on the TINY, instead of Arduino pins d2, d3, and d4. I didn’t use the test points.

  5. Brawrf

    I miss data on how the Arduino is powered here.
    I’d also like to know the current draw of the module, because it might be possible to pair everything up in a nice looking setup.

    Reply
    1. dilandou Post author

      Two choices for power, really. Either plug the arduino in separately when it’s needed for syncing, or tie it in to the USB cable before the diodes. As for current draw, device manager is reporting 260mA. I’m not going to argue with it.

      Reply
  6. Robin Chan

    personally i dont think your going to be able to use it to be able to sniff buttons using only commands.

    I think its a pretty simple USB HID interface? Arduinos can host these. I’m sure I’ve even heard of some people bit banging HID hosts.

    …try setting an arduino up in HID host mode and implementing a simple joypad sketch.

    Reply
  7. Pingback: Adaptador casero para usar el control inalámbrico del XBOX 360 con la PC : Tech-Freaks

  8. Pingback: XBOX 360 wireless controller module for OS X « repulsor.blog

  9. Benny Born

    Hey there. I got my hands on some of this RF-Modules (Rev H) and wired up everything correctly and in the same way as you schematics (except that I don’t use the Power SW and set up DATA and CLK to PIN 3&4 on Arduino). The module itself works great over USB but I cant get the LED initialization done. The clock just won’t change. One of my thoughts was that maybe the voltage of the DATA line is slightly too high (because it’s powered by arduinos 5V). Any ideas on that how to get this thing working? See the following link for the wiring: http://twitpic.com/8mirxx

    Thanks and best regards

    Reply
    1. dilandou Post author

      I’ve not personally noticed any problem with the logic voltage being too high. When you say the clock won’t change, you mean the module is keeping it high or low? Remember that the CLK pin is an output only; the module dictates the clock, not the Arduino.

      Reply
      1. Benny Born

        The clock is always kept low. I know that the CLK comes from the module.
        I thought maybe I broke the module because the 5v was too much for serial but connected to an xbox it’s still working fine…

      2. dilandou Post author

        Odd. Maybe the rev H has a different pinout? I know that the RF02 modules are different. Have you tried probing with a logic analyser or such?

      3. Benny Born

        Unfortunately I got no logic analyzer in here and I also searched the web for a pinout of the rev H – no success :

      4. dilandou Post author

        I would possibly suggest, in lack of a logic analyser, a look at using an Arduino as a logic analyser. There are plenty of projects out there, including a couple on the Arduino playground. That’s about the only thing I can suggest, I’m afraid.

      5. Benny Born

        I’ve found out, that CLOCK and DATA (if the module is connected to the xbox) runs at 1,8V. Afair you’re using an Arduino mini (which runs at 3,3V). 1,8V would trigger a HIGH on a mini while I’m using an Arduino Duemilanove (running at 5V) where 1,8V is slightly too little to trigger HIGH. So I guess to get this thing working I’d need some pull-up resistors – will try that these days.

    2. Pawli

      So did you get this REV. H (model: RF01) to work? If so, please tell how. I’m struggling to make it work with attiny13a.

      Reply
      1. JL

        I have a Rev. H as well. Had the same problem that the leds didnt light up. But i got it to sync. I am running a Arduino Uno rev 3 so I just connected 10k resistor from the 3.3V to both CLOCK and DATA. Now the leds light up as well.

    3. Albert

      I got my Rev H (RF 01) working today. Turns out that CLK pin needs a pull up as well. I was seeing the same thing as you were seeing where the CLK is always low, but once you put a pull up resistor on, you will see 250Hz clocks spiting out (when DATA is pulled low). I think DATA might need a open collector drive as well in the ideal case, but for this application, since we are only sending data to the RF module, hard driving 0 and 1 on DATA should be fine, which is how I got it working. Regarding voltage levels, I use 3.3V. I noticed that someone brought up that Rev H uses 1.8V, but I used 3.3V and it worked out fine.
      I think for early Revs you don’t need pull up for CLK pin, but for Rev H you definitely need one.
      Good luck!

      Reply
  10. engine24

    I cant get this to work with attiny13
    the code is from user cuba in post
    http://diru.org/wordpress/2011/03/wireless-xbox360-controller-on-a-pc-without-the-commercial-dongle/#comment-205
    #include
    #include
    #include
    #include

    #define B(x) (1<<x)
    #define sync_pin PB1 //sync pin
    #define data_pin PB3 //data line
    #define clock_pin PB4 //clock line

    #define digitalRead(x) (((PINB & B(x)) != 0)?1:0)
    #define digitalWrite(x, y) (y == 1 ? (PORTB |= B(x)):(PORTB &= ~B(x)))

    int led_cmd[10] = {0,0,1,0,0,0,0,1,0,0}; //Activates/initialises the LEDs, leaving the center LED lit.
    int anim_cmd[10] = {0,0,1,0,0,0,0,1,0,1}; //Makes the startup animation on the ring of light.
    int sync_cmd[10] = {0,0,0,0,0,0,0,1,0,0}; //Initiates the sync process.

    void sendData(int cmd_do[])
    {
    DDRB |= B(data_pin);
    PORTB &= ~B(data_pin);
    int prev = 1;
    for(int i = 0; i < 10; i++)
    {
    while (prev == digitalRead(clock_pin)); //detects change in clock
    prev = digitalRead(clock_pin);

    digitalWrite(data_pin, cmd_do[i]);

    while (prev == digitalRead(clock_pin)); //detects upward edge of clock
    prev = digitalRead(clock_pin);
    }
    PORTB |= B(data_pin);
    DDRB &= ~B(data_pin);
    }

    int __attribute__((OS_main)) main()
    {

    DDRB = 0b000000;
    DDRB |= 0b1;
    PORTB |= B(sync_pin);

    _delay_ms(2000);

    sendData(led_cmd);
    _delay_ms(50);
    sendData(anim_cmd);
    _delay_ms(50);

    for (;;)
    {
    if ( (PINB&B(sync_pin)) == 0 )
    {
    sendData(sync_cmd);
    _delay_ms(500);
    }
    }
    }

    Reply
      1. dilandou Post author

        Some people in the comments have mentioned that a code 10 has been caused by lack of power to the board. If you have a multimeter handy try checking the voltage you’re getting to the board.

        Alternatively, try reinstalling the drivers, after cleaning them off, and check that the hardware ID matches the one in the necessary modification.

      2. iZaQ

        haha It`s ALIVE 🙂 I add pull-up resistor (10kOhm) between microswitch and vcc.
        Thanks a lot. Xbox controller is great on PC.
        Sorry for my english

  11. Meta

    Hi

    Here is the source code for the PIC16F629.

    ;**********************************************************************
    ; This file is a basic code template for assembly code generation *
    ; on the PIC12F629. This file contains the basic code *
    ; building blocks to build upon. *
    ; *
    ; Refer to the MPASM User’s Guide for additional information on *
    ; features of the assembler (Document DS33014). *
    ; *
    ; Refer to the respective PIC data sheet for additional *
    ; information on the instruction set. *
    ; *
    ;**********************************************************************
    ; *
    ; Filename: xxx.asm *
    ; Date: *
    ; File Version: *
    ; *
    ; Author: *
    ; Company: *
    ; *
    ; *
    ;**********************************************************************
    ; *
    ; Files Required: P12F629.INC *
    ; *
    ;**********************************************************************
    ; *
    ; Notes: *
    ; *
    ;**********************************************************************

    list p=12f629 ; list directive to define processor
    #include ; processor specific variable definitions

    errorlevel -302 ; suppress message 302 from list file

    __CONFIG 0x3FD4

    ; ‘__CONFIG’ directive is used to embed configuration word within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See data sheet for additional information on configuration word settings.

    CBLOCK 0x15
    ENDC

    ;***** VARIABLE DEFINITIONS

    ;**********************************************************************
    ORG 0
    BSF STATUS,RP0
    CALL 0x3ff
    MOVWF T1CON
    BCF STATUS,RP0
    MOVLW 0x7
    MOVWF CMCON
    BSF STATUS,RP0
    MOVLW 0xfd
    MOVWF GPIO
    MOVLW 0x1
    MOVWF TMR0
    MOVLW 0xff
    MOVWF 0x15
    BCF STATUS,RP0
    BSF INTCON,T0IE
    CLRF 0x23
    BSF GPIO,GPIO1
    CALL 0xf
    CALL 0x78
    CALL 0xf
    GOTO 0x68
    CALL 0xb
    CALL 0xb
    CALL 0xb
    CALL 0xb
    CALL 0x7c
    CALL 0x9
    CALL 0x76
    BTFSC GPIO,GPIO5
    GOTO 0x6b
    BTFSS GPIO,GPIO5
    GOTO 0x6d
    CALL 0x7c
    CALL 0x9
    CALL 0x7a
    GOTO 0x64
    CLRF 0x23
    BSF GPIO,GPIO1
    RETURN
    MOVLW 0xaf
    GOTO 0x21
    MOVLW 0x84
    GOTO 0x21
    MOVLW 0x4
    GOTO 0x21
    MOVLW 0x90
    GOTO 0x21

    end

    Reply
    1. spikeysyco81

      how would i load this into a program for altering/playing around with? which program would i use? i have codeblocks installed but i dont seem to be able to paste it to it, it only ever takes the first line and then throws up errors

      Reply
  12. Jawsykilla

    Hi this hack is truly awesome, congrats and thanks for posting this. I managed to get it working in OSX using an Arduino to sync the controller. I got 2 controllers synced and they were recognised under Sys Prefs but all I did was unplug the RF module and back in via USB and it seems to have broken. Resetting the arduino re-initiates the boot animation on the RF module and then presseing the module power button I get the looking for sync animation. I press sync on my controllers and it appears to sync but then the controllers aren’t seen is system preferences any more? Any ideas?

    Reply
    1. dilandou Post author

      I’m not an OSX person myself, but as I’m fairly confident that the RF module and controllers have their sync information stored internally (they remember their controller/receiver pairs even across different machines) I would suggest that it’s more likely a driver problem on the OS side.

      Reply
  13. Parker

    I’m trying this with an RF01 board and an Arduino UNO R3. The pin 13 led stays lit but nothing happens on the RF board. Sometimes TX will blink if I press the button on the RF board but nothing happens. Looking at the serial output I see when I press the button:

    ÿ*«•Á¥¹¹
    Syncing.

    Not sure what I could be doing wrong. Wired pin 2 to the leftmost pin on the RF board (looking at it the same as the diagram in the article), pin 3 to the next pin, and pin 4 to the third pin over from the left. Any help is appreciated.

    Reply
  14. Pingback: Xbox 360 RF module and the Raspberry Pi | Astro Rats

  15. Pingback: Das Xbox 360 RF Modul und der Raspberry Pi | Astro Rats [german]

  16. Pingback: Das Xbox 360 RF Modul und der Raspberry Pi | Astro Rats

  17. Pingback: control your Xbox 360 RF Module with an Attiny45 | Astro Rats

  18. Pingback: Xbox 360 RF Modul mittels Attiny45 betreiben | Astro Rats / de

  19. Lascar Anderssen

    Very useful post, Thank you.

    I wonder though, every project I find online involves a PC to provide power and read controller signals. Is there a way to have Xbox RF module working with just Arduino/AVR/PIC with it’s own power supply or is PC/MAC absolutely necessary?

    Reply
  20. Vytenis

    I have made this also, although with a different code, because this wouldn’t work, but I have a problem. Every time I touch any of the wires or sometimes even wave my hand near the RF/Arduino, it goes completely nuts. Lights start to flicker, it turns on Synchronization on it’s own and so on. Maybe somebody has any clue what could be wrong. I’ve used Arduino Nano and Arduino Uno with the same results.

    Reply
    1. Vytenis

      Okay, I’ve found out what the problem was. I was wiring everything directly, thus it was picking various electrical noises and messing with my setup. A couple of pullup resistors fixed the thing right up.

      Reply
  21. Nick

    i assembled everything but it dosen’t work.. I tried troubleshooting with bad results. Can you help me?

    Reply
  22. ijekyll

    Hello there,
    I am a total newbie to electronics, and it’s been days and days since i started working on mine, given i had the H rev things were more complicated, and to worsen the stuff, i dont know much about electronics and stuff…

    But, i got it to work finally, and i wanted to share my setup, it may help people: http://img4.hostingpics.net/pics/480907xbox360rfbb.png

    Maybe you could add it to your post…

    Reply
    1. robot9706robot9706

      Hi!

      First of all sorry for my English 🙂

      I have some questions about the Rev H module, I would be very grateful if you could answer these 😀
      1) The middle (red) cable is the DATA, and the right (blue) is the CLOCK, right?
      2) How big are the resistors?
      3) Does any Microcontroller able to communicate with the module? (for ex.: NetDuino?)
      4) How many Hz is the CLOCK (250Hz)?
      5) Is this possible: for example a PSU makes interference in the cables and the microcontroller detects 50Hz?

      I don’t know what is the problem with my setup.. I just connected 2 digital I/Os with the 6 and 7 pin on the RF Module and I can’t communicate with it. I’m using a NetDuino Plus.

      The module is fully functionable, I installed the drivers and sometimes randomly LEDs start flashing on the RF Module, and start syncing. I managed to sync with my controller (without any microporcessor..) and it works great, but I want to use my controller with my Xbox and PC too, and it’s hard to sync with the module again..

      Reply
      1. iJekyll

        Hey, well, i’ll give the infos i have, although i am far away from understanding everything:

        1) Yes the middle (orange, not really red) is Data, the right (Blue) is Clock
        2) Well, small enough, 5mm without the pins, arround 1cm total, and they are 10Kohms resistors.
        3) Any microcontroller should be able to communicate with them if you get the programming right.
        4) Well, i really dont know how to answer this question, it is beyond my knowledge, if you can show me how to know that i’ll be glad to give you and answer back.
        5) i don’t think so, i have a lot bunch of electronics working permanently on my desk, and never had a problem with that since i soldered the module.

        I understand your problem, i evolved my module with a new design based on an Attiny85, it costs less than 1 dollar and it saves a lot of time, and that way i can play with my arduino without worrying about reuploading the code, if you want, i can give you the latest design i made, it shoud prove very efficient with the way you want to play with your module (xbox to pc, and then pc to xbox), do you want me to design that?

      2. robot9706

        @iJekyll Thanks for the reply.

        As I mentioned before English is not my native language, and with “How big are the resistors?” I wanted to ask that how many ohm (I just didn’t know how to ask that :/).

        Anyway I messed a little more with NetDuino and it turned out that it’s too slow, because of the Framework.
        RevH modules use about 320Hz to communicate (I’m not sure…).
        I don’t have an Ardunio so I solved my problem with a simple Serial Port, of course with level shifters.
        So now I’m happily using my RevH module both with my PC and XBox wihout any microcontroller 😀

  23. robot9706

    I know this is an old post, but I wanted to show you this 😀

    I don’t have an Ardunio, but I have a NetDuino, it’s CPU clock is 47MHz but it can’t read the 250Hz from the RF Module, The .NET framework slows down everything 😀

    So I came up with a new idea, and now I communicate with the RF Module without any microcontroller, I’m using a serial port 😀

    Here’s the link, if you’re interested: http://www.se7ensins.com/forums/threads/how-to-make-a-homemade-xbox-360-controller-wireless-receiver-for-pc.668839/page-14

    Reply
  24. Martin Ballantyne

    Hi, I’ve added some extra functionality to this so that if you hold down the sync button for more than a second the connected controllers will be turned off. Made the red lights fill up to show the time elapsed too. I did this using the RF module command research from http://tkkrlab.nl/wiki/XBOX_360_RF_Module.

    Additionally I’ve designed a 3D printable case for this when using an Arduino Duemilanove, which can also serve as the 3.3v supply for the module.

    Download:
    http://www.mediafire.com/download/z6b5k1n3s2n3u41/XboxControllerReceiver.zip

    Code:
    /* Arduino code to communicate with xbox 360 RF module.
    Original work by (yaywoop)
    Additional ideas from Alexander Martinez
    Modified by dilandou (www.dilandou.com, http://www.diru.org/wordpress)
    Controller turn off added by Martin Ballantyne using research from http://tkkrlab.nl/wiki/XBOX_360_RF_Module
    First sends LED initialisation code followed by LED startup animation code, then sleeps until a button press for sync command.
    If the sync button is held down and released after 1000ms the connected controllers will be turned off. Otherwise the sync command will initiate.
    RF module must be powered with 3.3V, two diodes in series with USB 5v will do. Connect the USB wires to a host computer, and the data and serial wires to Arduino.
    of course, make sure to have a common ground */

    #include

    #define sync_pin 2 //power button repurposed for sync button (pin 5 on the module)
    #define data_pin 3 //data line (pin 6 on the module)
    #define clock_pin 4 //clock line (pin 7 on module)

    int led_cmd[10] = {0,0,1,0,0,0,0,1,0,0}; //Activates/initialises the LEDs, leaving the center LED lit.
    int led_timer_red_1[10] = {0,0,1,0,1,1,1,0,0,0}; //Set quadrant 1 to red
    int led_timer_red_2[10] = {0,0,1,0,1,1,1,1,0,0}; //Set quadrant 1 and 2 to red
    int led_timer_red_3[10] = {0,0,1,0,1,1,1,1,0,1}; //Set quadrant 1, 2 and 4 to red
    int led_timer_red_4[10] = {0,0,1,0,1,1,1,1,1,1}; //Set quadrant 1, 2, 3 and 4 to red
    int led_red_off[10] = {0,0,1,0,1,1,0,0,0,0}; //Set quadrant 1, 2, 3 and 4 to off

    int anim_cmd[10] = {0,0,1,0,0,0,0,1,0,1}; //Makes the startup animation on the ring of light.
    int sync_cmd[10] = {0,0,0,0,0,0,0,1,0,0}; //Initiates the sync process.
    int turn_off_cmd[10] = {0,0,0,0,0,0,1,0,0,1}; //Turns off the connected controllers.

    volatile boolean sync_pressed = 0;
    int sync_hold_time = 0;
    boolean turn_off_controllers = false;

    void sendData(int command[])
    {
    pinMode(data_pin, OUTPUT);
    digitalWrite(data_pin, LOW); //start sending data.

    int previous_clock = 1;
    for(int i = 0; i = 1000)
    {
    sendData(led_timer_red_4);
    }
    else if(held_time >= 750)
    {
    sendData(led_timer_red_3);
    }
    else if(held_time >= 500)
    {
    sendData(led_timer_red_2);
    }
    else if(held_time >= 250)
    {
    sendData(led_timer_red_1);
    }
    else
    {
    sendData(led_red_off);
    }
    }

    void initLEDs()
    {
    sendData(led_cmd);
    sendData(anim_cmd);
    }

    void wakeUp()
    {
    sync_pressed = 1;
    }

    void sleepNow()
    {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN); // set sleep mode
    sleep_enable(); //enable sleep bit
    attachInterrupt(0, wakeUp, LOW);
    sleep_mode();
    sleep_disable(); //disable sleep bit
    detachInterrupt(0); // disables interrupt 0 on pin 2
    }

    void setup()
    {
    Serial.begin(9600);
    pinMode(sync_pin, INPUT);
    digitalWrite(sync_pin,HIGH);
    pinMode(data_pin, INPUT);
    pinMode(clock_pin, INPUT);
    delay(2000);

    initLEDs();
    }

    void loop()
    {
    // Only sleep if the sync button is not held down
    if(!sync_pressed)
    {
    sleepNow();
    }

    delay(200);

    if(sync_pressed)
    {
    Serial.print(“Sync held time (ms): “);
    Serial.println(sync_hold_time, DEC);

    setHeldLEDs(sync_hold_time);

    // Count 1000ms, if elapsed the user wants to turn off their controllers
    if(sync_hold_time >= 1000)
    {
    turn_off_controllers = true;
    sync_hold_time = 1000;
    }

    // Initiate the user’s action when they release the sync button
    if (digitalRead(sync_pin))
    {
    setHeldLEDs(0);

    if(turn_off_controllers)
    {
    Serial.println(“Turning off controllers.”);
    sendData(turn_off_cmd);

    turn_off_controllers = false;
    }
    else
    {
    Serial.println(“Syncing controllers.”);
    sendData(sync_cmd);
    }

    // Action complete, reset hold time and button state
    sync_hold_time = 0;
    sync_pressed = false;
    }
    else
    {
    sync_hold_time += 200;
    }
    }
    }

    Reply
  25. H43ng3r

    Hello,
    it tried to get this running on a Arduino Mega2560.
    But it doesn´t work.
    But nothing happens. Cabel are soldered right.

    I think the problem is that the arduino doesn,t recognize the Clock.
    It tested this with the following Code.
    The serial monitor only shows 0 . Why?

    Does anybody have a solution for this Problem?

    PS: The Code above me is getting a lot of compiler errors.

    Reply
  26. Pingback: Xbox 360 RF module + Arduino -Use Arduino for Projects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s