Mega ADK avec Joystick

Bonjours,
Je possède une carte arduino mega 2560 adk, je veux m’en servir pour lire les informations provenant d’un joystick USB et ensuite contrôler un robot par les pins I/O.
J’ai insérer dans le logiciel les librairies USB host shield et USB Joystick. J’ai utilisé l’exemple donné, et le joystick est bien détecté : les boutons ainsi que les potentiomètres (je vois les valeur dans le "serial monitor").

Mon problème est que je n’arrive pas a trouver comment lire si un bouton est activé ou non, dans l’exemple il n’y a aucune variable déclarée que je pourrais utilisée pour lire leur état. J’ai beau regarder dans les documentations de la librairie je ne trouve pas la fonction recherchée.

Voici l'exemple du logiciel:

// usbjoystick_test
// This sketch demonstrates simple use of the USBJoystick library
// It intialises the library, establishes callbacks for when inputs change
// and prints out details whenever an input changes and a callback is called.
//
// USB Host Shield uses an interrupt line, but does not establish an interrupt callback
// Note special requirements in documentation if you are using an older version of the USB Host Shield and a newer 
// version of the USB_Host_Shield library.
// Note special requirements to configure the WiShield librray to support the UDP application. 
// mikem@open.com.au

#include <Usb.h>
#include <USBJoystick.h>

// Our singleton joystick
USBJoystick joy;

// Here we define some callbacks thgat will be called when a stick, button
// or hat switch changes. You can also have a callback called for every polled value, if you prefer.
// Alternatively, you can use the *Value() data accessory to asynchronously get the last read value
// for the sticks, buttons and hats.

// stick will be one of USBJOYSTICK_STICK_*
void stickValueDidChangeCallback(uint8_t stick, uint8_t value)
{
    Serial.print("stickValueDidChangeCallback: ");
    Serial.print(stick, DEC);
    Serial.print(": ");
    Serial.print(value, DEC);
    Serial.println("");
}
// button will be one of USBJOYSTICK_BUTTON_*
void buttonValueDidChangeCallback(uint8_t button, uint8_t value)
{
    Serial.print("buttonValueDidChangeCallback: ");
    Serial.print(button, DEC);
    Serial.print(": ");
    Serial.print(value, DEC);
    Serial.println("");
}
// hat will be one of USBJOYSTICK_HAT_*
// value will be one of USBJOYSTICK_HAT_POS_*
void hatValueDidChangeCallback(uint8_t hat, uint8_t value)
{
    Serial.print("hatValueDidChangeCallback: ");
    Serial.print(hat, DEC);
    Serial.print(": ");
    Serial.print(value, DEC);
    Serial.println("");
}

void setup()
{
  Serial.begin(9600);

  // Specify callbacks to call when inputs change
  joy.setStickValueDidChangeCallback(stickValueDidChangeCallback);
  joy.setButtonValueDidChangeCallback(buttonValueDidChangeCallback);
  joy.setHatValueDidChangeCallback(hatValueDidChangeCallback);
  joy.init();
}

void loop()
{
  joy.run();
}

Sauriez vous comment lire les informations des boutons voir meme des potentiomètre ?

Merci

Personne ne connaitrait meme pas la moindre piste ???

Salut,

regarde si ceci te convient :

/* This demo uses the UsbJoystick.h library, a library based on AVRUSB from ObDev
 * It demonstrates a 6-axis joystick with 4 buttons by reading all the analog ports and
 * digtal pins 9,10,11,and 12
 * Adapted from the UsbKeyboard.h library from Phil Lindsay
 *
 * by Michel Gutlich   19-8-2008
 */

#include <UsbJoystick.h>

unsigned short a2dValue;
unsigned char high;
unsigned char low;
unsigned char temp;
unsigned char report[8];


void setup() {
  
  pinMode (9,INPUT);
  pinMode (10,INPUT);
  pinMode (11,INPUT);
  pinMode (12,INPUT);
  
}

void loop () {
  UsbJoystick.refresh(); // Let the AVRUSB driver do some houskeeping
  calculateReport(); // Jump to our port read routine that orders the values
  UsbJoystick.sendJoystick(report[0],report[1],reportBuffer[2],report[3],report[4],report[5],report[6],report[7]); // send the values
}

void calculateReport() {  //The values read from the analog ports have to be ordered in a way the HID protocol wants it; a bit confusing.

  a2dValue = analogRead(0);
  high = a2dValue >> 8;
  low = a2dValue & 255;
  report[0] = low;
  temp = high;

  a2dValue = analogRead(1);
  high = a2dValue >> 6;
  low = a2dValue & 63;
  report[1] = (low << 2) + temp;
  temp = high;

  a2dValue =analogRead(2);
  high = a2dValue >> 4;
  low = a2dValue & 15;
  report[2] = (low << 4) + temp;
  temp = high;

  a2dValue = analogRead(3);
  high = a2dValue >> 2;
  low = a2dValue & 3;
  report[3] = (low << 6) + temp;
  temp = high;

  high = 0;
  low = 0;
  report[4] = temp;
  temp = high;

  a2dValue = analogRead(4);
  high = a2dValue >> 8;
  low = a2dValue & 255;
  report[5] = low + temp;
  temp = high;

  a2dValue = analogRead(5);
  high = a2dValue >> 6;
  low = a2dValue & 63;
  report[6] = (low << 2) + temp;
  temp = high;

  // 4 buttons , tossed around

  report[7] = (temp & 15) + (digitalRead(9) << 4) +  (digitalRead(10) << 5) +  (digitalRead(11) << 6) +  (digitalRead(12) << 7);

}

La source ici : Arduino | Elektronica Voor Jou

++