Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Joystick2.h"
- struct Controle{
- char x;
- char y;
- unsigned char botoes;
- };
- Controle controles[2];
- void setup() {
- // put your setup code here, to run once:
- Joystick[0].begin();
- Joystick[1].begin();
- memset(controles, sizeof(Controle)*2,0);
- controles[1].botoes = 0b11010110; // estado qualquer para os botões de um controlador
- controles[1].x = 127;
- controles[1].y = 127;
- }
- bool tick(unsigned long* contador, unsigned long timeout){
- if (millis() >= contador + timeout){
- contador = millis();
- return true;
- }else{
- return false;
- };
- }
- void loop() {
- static unsigned long timer_contador=0;
- static unsigned long timer_envio =0;
- int i,b;
- if(tick(timer_contador,500)){
- for(i=0;i<2;i++){
- controles[i].botoes++;
- controles[i].x += 25;
- controles[i].y += 25;
- };
- };
- if(tick(timer_envio,10)){
- for(i=0;i<2;i++){
- for(b=0;b<8;b++){
- Joystick[i].setXAxis ( controles[i].x );
- Joystick[i].setYAxis ( controles[i].y );
- Joystick[i].setButton(b, bitRead(controles[i].botoes,b));
- };
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment