Grazie Funzionaaaaaa!!!
Ho risolto meno male.
Non con il tuo sketch, ma grazie alla tua risposta mi sono messo di nuovo a smanettare e ho scoperto che era una massa non ben saldata, mannaggia a me ormai non ci vedo più da vicino.
Funziona alla grande, senza ghosts, reazioni immediate, ripetizione corretta.
Bene, bene sono contento, finalmente.
A volte basta poco, anche un piccolo tentativo ulteriore da fare per capire il guaio.
Ero un po sconfortato , avendo rimosso il keyboard hack dal cab per farci stare l ' MVS e l ' ST-V sul cablaggio Jamma, e non riuscivo più a gestirci il pc.
ti posto il mio di sketch, ovviamente scopiazzato, da qui:
http://mahoneytech.com/blog/2013/03/17/ ... ontroller/
Molto simile al tuo, con gli inputs gestiti in array, veloce e preciso.
Se hai problemi anche tu, fammi sapere, magari ti posso essere utile.
Codice: Seleziona tutto
/*
* Space Invaders TV Game Joystick test sketch
* Chris Mahoney / March 17, 2013
*
* Use keyboard emulation of Leonardo to press keyboard
* keys when switches are triggered on Space Invaders controller.
*/
//Variables for the buttons
/*
* Switch order:
* (8) Ground, L, U, R, D, B, A (2)
*/
// Arduino pin -> function
int buttonLeft=6, buttonUp=4, buttonRight=7, buttonDown=5, buttonB=1, buttonA=0, buttonC=2, buttonD=3, buttonCoin1=8, buttonStart=9, buttonStart2=21, buttonLeft2=15, buttonUp2=14, buttonRight2=16, buttonDown2=10, buttonB2=19, buttonA2=20, buttonC2=18;
// Set all pins high before setup()
int prevLeft = HIGH, prevUp = HIGH, prevRight = HIGH, prevDown = HIGH, prevB = HIGH, prevA = HIGH, prevC = HIGH, prevD = HIGH, prevCoin1 = HIGH, prevStart = HIGH, prevStart2 = HIGH, prevLeft2 = HIGH, prevUp2 = HIGH, prevRight2 = HIGH, prevDown2 = HIGH, prevB2 = HIGH, prevA2 = HIGH, prevC2 = HIGH;
// Array of button pins
int buttons[18] = {buttonLeft, buttonUp, buttonRight, buttonDown, buttonB, buttonA, buttonC, buttonD, buttonCoin1, buttonStart, buttonStart2, buttonLeft2, buttonUp2, buttonRight2, buttonDown2, buttonB2, buttonA2, buttonC2};
// Previous state of buttons
int prevButtons[18] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
// Actual ASCII values to "press"
int buttonNames[18] = {KEY_LEFT_ARROW, KEY_UP_ARROW, KEY_RIGHT_ARROW, KEY_DOWN_ARROW, KEY_LEFT_ALT, KEY_LEFT_CTRL, 32, KEY_LEFT_SHIFT, 53, 49, 50, 97, 115, 113, 114, 102, 100, 103};
int pinCount = 18; // # of pins
void setup(void)
{
// Set all pins INPUT to begin
for (int pin = 0; pin < pinCount; pin++) {
pinMode(pin, INPUT);
}
// Enable keyboard interaction (REQUIRES LEONARDO/MICRO)
Keyboard.begin();
}
void loop(void)
{
// Run each pin each loop
for (int pin = 0; pin < pinCount; pin++) {
// Get pin value
int buttonState = digitalRead(buttons[pin]);
// Only process if different than last check
if (buttonState != prevButtons[pin]) { // State change, process it
// Pressed?
if (buttonState == HIGH) {
Keyboard.press(buttonNames[pin]);
}
// Released?
if (buttonState == LOW) {
Keyboard.release(buttonNames[pin]);
}
// Set new previous state
prevButtons[pin] = buttonState;
} // End state change
// Delay to avoid freakouts if experienced
// delay(10);
}
}