// IMPORTANTE instalar drivers especiales para Digispark ATTINY85, gestor de tarjetas y tarjeta // https://kawaii-tech.com/instalando-drivers-para-digispark-2/ // https://www.digilogic.es/digispark-attiny-usb-un-arduino-en-miniatura/ //Codigo modificado tomado de: /* 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 /*Al utilizar la tarjeta Digispark Attiny85 las interrupciones no funcionan bien, asi que no las utilizo, posiblemente por conflicto con el bootloader. Pudiera suceder lo mismo con Arduino Leonardo o cualquier otro que tenga bootloader integrado con USB nativo.*/ #define sync_pin 2 //power button repurposed for sync button (pin 5 on the module) #define data_pin 1 //data line (pin 6 on the module) #define clock_pin 0 //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. //int all_red[10] = {0,0,1,0,1,1,1,1,1,1}; //int all_orange[10] = {0,0,1,1,1,0,0,0,0,0}; int CLEAR_ERROR[10] = {0,0,1,1,0,0,0,0,0,0}; volatile boolean sync_enable = 0; void setup() { pinMode(sync_pin, INPUT_PULLUP); digitalWrite(sync_pin,HIGH); pinMode(data_pin, INPUT); pinMode(clock_pin, INPUT); delay(2000); initLEDs(); // sendData(sync_cmd); } 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); sendData(CLEAR_ERROR); delay(50); } //void clr_errors(){ // sendData(CLEAR_ERROR); // delay(50); // sendData(led_cmd); // delay(50); // sendData(anim_cmd); // delay(50); //} void loop(){ sync_enable = !digitalRead(sync_pin); if(sync_enable==1) { sendData(sync_cmd); sync_enable = 0; delay(10000); digitalWrite(sync_pin,HIGH); } }