Ciao,
Ho trovato uno sketch e modificato per arduino micro pro
siccome di informatica non so nulla, come posso fare per creare 16 bottoni con 4 righe e 4 colonne?
#include <Joystick.h>
#define PINS 13
#define ENABLE_ANALOG1 true
int Z = A1;
int rudder = A2;
int throttle = A3;
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, PINS, 0,
true, true, false, false, false, false, false, false, false, false, false);
class CButton {
public:
int pin = NULL;
int lastState = 0;
CButton(int p) {
pin = p;
}
};
CButton Buttons[PINS] ={2,3,4,5,6,7,8,9,10,16,14,15,A0};
void setup() {
for(int i=0 ; i<PINS ;i++) {
pinMode(Buttons[i].pin, INPUT_PULLUP);
}
Joystick.begin();
if (ENABLE_ANALOG1) {
Joystick.setZAxisRange(-512, 512);
Joystick.setRudderRange(0, 1023);
Joystick.setThrottleRange(0, 1023);
}
}
void JButtonStates() {
if (ENABLE_ANALOG1) {
Joystick.setZAxis(analogRead(Z) - 512);
Joystick.setRudder(analogRead(rudder));
Joystick.setThrottle(analogRead(throttle));
}
for (int i = 0; i < PINS; i++) {
int currentState = !digitalRead(Buttons[i].pin);
if (currentState != Buttons[i].lastState) {
Joystick.setButton(i, currentState);
Buttons[i].lastState = currentState;
}
}
}
void loop() {
JButtonStates();
delay(50);
}
grazie