document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include "Joystick2.h"
  2.  
  3. struct Controle{
  4.   char x;
  5.   char y;
  6.   unsigned char botoes;
  7. };
  8.  
  9. Controle controles[2];
  10.  
  11. void setup() {
  12.   // put your setup code here, to run once:
  13.   Joystick[0].begin();
  14.   Joystick[1].begin();
  15.  
  16.   memset(controles, sizeof(Controle)*2,0);
  17.  
  18.   controles[1].botoes = 0b11010110; // estado qualquer para os botões de um controlador
  19.   controles[1].x = 127;
  20.   controles[1].y = 127;
  21. }
  22. bool tick(unsigned long* contador, unsigned long timeout){
  23.   if (millis() >= contador + timeout){
  24.     contador = millis();
  25.     return true;
  26.   }else{
  27.     return false;
  28.   };
  29. }
  30. void loop() {
  31.   static unsigned long timer_contador=0;
  32.   static unsigned long timer_envio   =0;
  33.  
  34.   int i,b;
  35.   if(tick(timer_contador,500)){
  36.     for(i=0;i<2;i++){
  37.       controles[i].botoes++;
  38.       controles[i].x += 25;
  39.       controles[i].y += 25;
  40.     };  
  41.   };
  42.  
  43.   if(tick(timer_envio,10)){
  44.     for(i=0;i<2;i++){
  45.       for(b=0;b<8;b++){
  46.         Joystick[i].setXAxis ( controles[i].x );
  47.         Joystick[i].setYAxis ( controles[i].y );
  48.         Joystick[i].setButton(b, bitRead(controles[i].botoes,b));
  49.       };
  50.     };
  51.   }
  52. }
');