Button Box con Arduino Leonardo


ciao tutti.
vorrei fare una buttonbox con arduino, tal proposito ho trovato questo progetto:

http://mheironimus.blogspot.it/2015/03/add-usb-game-controller-to-arduino.html

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 farlo?

scusa ma non capisco...

cosa vuoi fare?

sii più dettagliato

sul sito è tutto ben commentato
queste sono le funzioni della libreria:

code: [select]

introduction
arduinoleonardofrontout of box arduino leonardo , arduino micro appear host computer generic keyboard , mouse. article discusses how arduino leonardo , arduino micro can appear generic game controller. project work arduino products based on atmega32u4 microcontroller (i.e. arduino leonardo , arduino micro). not work arduino uno, because based on atmega328 microcontroller.

arduinomicrofrontthe arduino generic game controller provides following:

x, y, , z axis
32 buttons
x, y, , z axis rotation
rudder
throttle
2 point of view hat switches
updating arduino code
first make backup copy of following 2 files in "%programfiles%\arduino\hardware\arduino\avr\cores\arduino" folder:

usbapi.h
hid.cpp
replace these 2 files following add generic game controller arduino leonardo , arduino micro:

usbapi.h
hid.cpp
running test sketch
compile , upload usbjoysticktest.ino sketch file onto arduino leonardo or arduino micro using arduino software (ide). have tested using version 1.6.1 of software.

the following steps windows 7. if have different version of windows or different operating system, these steps may differ.

go windows control panel , select "hardware , sound".

control panel

then select "devices , printers".

hardware , sound
 
the arduino micro or arduino leonardo should appear in list of devices.

devices
 
next right mouse click on arduino leonardo or arduino micro display settings menu.

drop down settings
 
select "game controller settings" "game controllers" dialog.

game controllers
 
the arduino micro or arduino leonardo should appear in list of installed game controllers. select arduino micro or arduino leonardo , click properties button display game controller test dialog.

arduino game controller settings

while dialog has focus, ground pin a0 on arduino activate test script. test script test game controller functionality in following order:

32 buttons
throttle , rudder
x , y axis
z axis
2 hat switches
x , y axis rotation
joystick library
now arduino leonardo or arduino micro has joystick library, arduino can used custom game controller projects. following describes joystick library included in updated usbapi.h , hid.cpp files.

joystick.begin(bool initautosendstate)
starts emulating game controller connected computer. default methods update game controller state immediately. if initautosendstate set false, joystick.sendstate method must called update game controller state.

joystick.end()
stops game controller emulation connected computer.

joystick.setxaxis(byte value)
sets x axis value. range -127 127 (0 center).

joystick.setyaxis(byte value)
sets y axis value. range -127 127 (0 center).

joystick.setzaxis(byte value)
sets z axis value. range -127 127 (0 center).

joystick.setxaxisrotation(int value)
sets x axis rotation value. range 0° 360°.

joystick.setyaxisrotation(int value)
sets y axis rotation value. range 0° 360°.

joystick.setzaxisrotation(int value)
sets z axis rotation value. range 0° 360°.

joystick.setbutton(byte button, byte value)
sets state of specified button. button 0-based button number (i.e. button #1 0, button #2 1, etc.). value 1 if button pressed , 0 if button released.

joystick.pressbutton(byte button)
press indicated button. button 0-based button number (i.e. button #1 0, button #2 1, etc.).

joystick.releasebutton(byte button)
release indicated button. button 0-based button number (i.e. button #1 0, button #2 1, etc.).

joystick.setthrottle(byte value)
sets throttle value. range 0 255.

joystick.setrudder(byte value)
sets rudder value. range 0 255.

joystick.sethatswitch(byte hatswitch, int value)
sets value of specified hat switch. hatswitch 0-based (i.e. hat switch #1 0 , hat switch #2 1). value 0° 360°, in 45° increments. value less 45° rounded down (i.e. 44° rounded down 0°, 89° rounded down 45°, etc.).

joystick.sendstate()
sends updated joystick state host computer. needs called if autosendstate false (see joystick.begin more details).



la prima inizializza
la seconda termina la connessione

dalla terza alla penultima sono le funzioni del joystick

l'ultima invia valori al pc


butto giù uno schema logico:

code: [select]

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








Arduino Forum > International > Italiano > Software (Moderator: leo72) > Button Box con Arduino Leonardo


arduino

Comments