Button Box con Arduino Leonardo

Ciao a tutti.
Vorrei fare una buttonbox con Arduino, a tal proposito ho trovato questo progetto:

Al momento la mia scheda Leonardo viene riconosciuta come controller Joystick ma è da programmare perchè lo sketch allegato serve solo per testare l'hardware.

Avrei bisogno di aiuto per capire per capire come fare, ho una piccola base di programmazione ma Arduino mi è sconosciuto chi mi da una mano a farlo?

Scusa ma non capisco...

Cosa vuoi fare?

Sii più dettagliato

Sul sito è tutto ben commentato
Queste sono le funzioni della libreria:

Introduction
ArduinoLeonardoFrontOut of the box the Arduino Leonardo and the Arduino Micro appear to the host computer as a generic keyboard and mouse. This article discusses how the Arduino Leonardo and the Arduino Micro can also appear as a generic Game Controller. This project will only work with Arduino products based on the ATmega32u4 microcontroller (i.e. the Arduino Leonardo and the Arduino Micro). It will not work with the Arduino Uno, because it is based on the ATmega328 microcontroller.

ArduinoMicroFrontThe Arduino generic Game Controller provides the following:

X, Y, and Z axis
32 buttons
X, Y, and Z axis rotation
Rudder
Throttle
2 Point of View Hat Switches
Updating the Arduino Code
First make a backup copy of the following two files in the “%PROGRAMFILES%\Arduino\hardware\arduino\avr\cores\arduino” folder:

USBAPI.h
HID.cpp
Replace these two files with the following to add a generic Game Controller to the Arduino Leonardo and the Arduino Micro:

USBAPI.h
HID.cpp
Running the Test Sketch
Compile and upload the UsbJoystickTest.ino sketch file onto the Arduino Leonardo or the Arduino Micro using the Arduino Software (IDE). I have tested this using version 1.6.1 of the software.

The following steps are for Windows 7. If you have a different version of Windows or a different operating system, these steps may differ.

Go to the Windows Control Panel and select “Hardware and Sound”.

Control Panel

Then select “Devices and Printers”.

Hardware and Sound
 
The Arduino Micro or Arduino Leonardo should appear in the list of devices.

Devices
 
Next right mouse click on the Arduino Leonardo or Arduino Micro to display the settings menu.

Drop Down Settings
 
Select “Game controller settings” to get to the “Game Controllers” dialog.

Game Controllers
 
The Arduino Micro or Arduino Leonardo should appear in the list of installed game controllers. Select the Arduino Micro or Arduino Leonardo and click the Properties button to display the game controller test dialog.

Arduino Game Controller Settings

While this dialog has focus, ground pin A0 on the Arduino to activate the test script. The test script will test the game controller functionality in the following order:

32 buttons
throttle and rudder
X and Y Axis
Z Axis
2 Hat Switches
X and Y Axis Rotation
Joystick Library
Now that the Arduino Leonardo or Arduino Micro has the Joystick library, the Arduino can be used for custom game controller projects. The following describes the Joystick library that is included in the updated USBAPI.h and HID.cpp files.

Joystick.begin(bool initAutoSendState)
Starts emulating a game controller connected to a computer. By default all methods update the game controller state immediately. If initAutoSendState is set to false, the Joystick.sendState method must be called to update the game controller state.

Joystick.end()
Stops the game controller emulation to a connected computer.

Joystick.setXAxis(byte value)
Sets the X axis value. Range -127 to 127 (0 is center).

Joystick.setYAxis(byte value)
Sets the Y axis value. Range -127 to 127 (0 is center).

Joystick.setZAxis(byte value)
Sets the Z axis value. Range -127 to 127 (0 is center).

Joystick.setXAxisRotation(int value)
Sets the X axis rotation value. Range 0° to 360°.

Joystick.setyAxisRotation(int value)
Sets the Y axis rotation value. Range 0° to 360°.

Joystick.setZAxisRotation(int value)
Sets the Z axis rotation value. Range 0° to 360°.

Joystick.setButton(byte button, byte value)
Sets the state of the specified button. The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.). The value is 1 if the button is pressed and 0 if the button is released.

Joystick.pressButton(byte button)
Press the indicated button. The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).

Joystick.releaseButton(byte button)
Release the indicated button. The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).

Joystick.setThrottle(byte value)
Sets the throttle value. Range 0 to 255.

Joystick.setRudder(byte value)
Sets the rudder value. Range 0 to 255.

Joystick.setHatSwitch(byte hatSwitch, int value)
Sets the value of the specified hat switch. The hatSwitch is 0-based (i.e. hat switch #1 is 0 and hat switch #2 is 1). The value is from 0° to 360°, but in 45° increments. Any value less than 45° will be rounded down (i.e. 44° is rounded down to 0°, 89° is rounded down to 45°, etc.).

Joystick.sendState()
Sends the updated joystick state to the host computer. Only needs to be called if AutoSendState is false (see Joystick.begin for more details).

La prima inizializza
La seconda termina la connessione

Dalla terza alla penultima sono le funzioni del joystick

L'ultima invia i valori al PC

Butto giù uno schema logico:

Void Setup
{
Joystick.begin(false);
Joystick.

sendState();
}

.setButton(1, 1)

}

Void Loop{
Joystick.SendState(1,1);
}

In teoria dovresti vedere il bottone 1 acceso.

Potresti attaccare un pulsante ad arduino e mettere il digital reed al posto di 1 dopo la virgola nel joystick.sendStare e spostarlo nel loop

Grazie mille della risposta.
Quello che volevo fare è una pulsantiera e non riuscivo a capire come si potesse utilizzare 32 pulsanti + hat swich e potenziometri tutto sulla stessa scheda poi ho trovato un esempio di Multiplex buttons e sto lavorando su quella. Al momento mi sembra tutto funzioni correttamente.

Ciao a tutti,

Sto cercando di fare una pulsantiera con 32 pulsanti + hat swich e potenziometri, pero capisco molto poco di codici Arduino.

Torque80, si dispone già di uno schizzo che funziona, me lo poi passare?

Grazie in anticipo :smiley: