Salve. Come primo progetto -siate pazienti- sto cercando di realizzare una tastiera per macro, che da una matrice di pulsanti mi digiti delle combinazioni di tasti e/o dei testi ricorrenti.
Mi sono basato su un Teensy 2.0 e il codice di Arduino Forum.
Ho inserito nel loop, per vedere se l'errore era al suo interno, un po' di codice per il LED. Bene, il LED lampeggia come dovrebbe, eppure non riesco a far funzionare la tastiera come dovrebbe.
Il Teensy è configurato nell'IDE come USB, keyboard+mouse+ joystick,
a questo punto suppongo di aver sbagliato qualcosa nell'accoppiamento dei casi, o nelle dichiarazioni, ma non riesco a capire cosa.
Grazie in anticipo.
#include <Keypad.h>
// Author: Nick Gammon - mod sardauker
// Date: 5th July 2012
// Modified: 22 October 2012int led = 11;
const byte ROWS = 6;
const byte COLS = 8;char keys[ROWS][COLS] = {
{'31', '61', '91', '#1', '*2', '72', '42', '12'},
{'21', '51', '81', '01', '02', '82', '52', '22'},
{'11', '41', '71', '*1', '#2', '92', '62', '32'},
{'33', '63', '93', '#3', '*4', '74', '44', '14'},
{'23', '53', '83', '03', '04', '84', '54', '24'},
{'13', '43', '73', '*3', '#4', '94', '64', '34'},
};byte rowPins[ROWS] = {11, 12, 13, 14, 15, 16}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {1, 2, 3, 4, 5, 6, 7, 8}; //connect to the column pinouts of the keypad// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );void setup ()
{
// initialize control over the keyboard:
Keyboard.begin();
pinMode (ledPin, OUTPUT);
} // end of setupvoid loop ()
{//heartbeat
digitalWrite(led, HIGH); // turn the LED on
delay(200); // lascia acceso
digitalWrite(led, LOW); // spegne
delay(200); // pausa
digitalWrite(led, HIGH); // turn the LED on
delay(200); //lascia acceso
digitalWrite(led, LOW); // fine hearthbeat
delay(1000); // wait for a secondbyte key = kpd.getKey();
if (!key)
return;switch (key)
{
case '11': Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT | MODIFIERKEY_SHIFT ); Keyboard.println (F("11")); Keyboard.set_modifier(0); break;
case '21': Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT | MODIFIERKEY_SHIFT ); Keyboard.set_key1(KEY_DELETE); Keyboard.send_now(); Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now() ; break;
case '31': Keyboard.println (F(" 31")); break;
case '41': Keyboard.println (F(" 41")); break;// e così via...
} // end of switch
} // end of loop