//Se voglio utilizzare il keyPad non posso usare la sua libreria altrimenti va in contrasto con la libreria UsbKeyboard #include "UsbKeyboard.h" const int numRows = 4; // numero di righe const int numCols = 4; // numero di colonne const int debounceTime = 20; // millisecondi necessari allo switch per diventare stabile // Mappa dei caratteri sul tastierino const char keymap[numRows][numCols] = { { '1', '2', '3', 'A' } , { '4', '5', '6', 'B' } , { '7', '8', '9', 'C' } , { '*', '0', '#', 'D' } }; // Definisco i pin connessi alle righe o alle colonne const int rowPins[numRows] = {6, 7, 8, 9}; // Pin di arduino connessi ai pin 1,2,3 e 4 delle righe del keypad const int colPins[numCols] = {10, 11, 12, 13}; // Pin di arduino connessi ai pin 5,6,7 e 8 delle colonne del keypad int key; void setup() { for (int row = 0; row < numRows; row++) { pinMode(rowPins[row],INPUT); // Imposta i pun delle righe come input digitalWrite(rowPins[row],HIGH); // Imposta le righe a HIGH (inattiva) - abilita le resistenze di pull-ups } for (int column = 0; column < numCols; column++) { pinMode(colPins[column],OUTPUT); // Setta i pin delle colonne come input digitalWrite(colPins[column],HIGH); // Imposta le colonne a HIGH (inattiva) - abilita le resistenze di pull-ups } TIMSK0 &= !(1 << TOIE0); cli();// disabilita l'interrupt usbDeviceDisconnect(); delayMs(250); usbDeviceConnect(); sei();//riabilita l'interrupt } void loop() { UsbKeyboard.update(); key = getKey(); if(key != 0){ switch(key) { case 42: UsbKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); break; case 35: UsbKeyboard.sendKeyStroke(KEY_SPACE); break; case 48: UsbKeyboard.sendKeyStroke(KEY_0); break; case 49: UsbKeyboard.sendKeyStroke(KEY_1); break; case 50: UsbKeyboard.sendKeyStroke(KEY_2); break; case 51: UsbKeyboard.sendKeyStroke(KEY_3); break; case 52: UsbKeyboard.sendKeyStroke(KEY_4); break; case 53: UsbKeyboard.sendKeyStroke(KEY_5); break; case 54: UsbKeyboard.sendKeyStroke(KEY_6); break; case 55: UsbKeyboard.sendKeyStroke(KEY_7); break; case 56: UsbKeyboard.sendKeyStroke(KEY_8); break; case 57: UsbKeyboard.sendKeyStroke(KEY_9); break; case 65: UsbKeyboard.sendKeyStroke(KEY_A); break; case 66: UsbKeyboard.sendKeyStroke(KEY_B); break; case 67: UsbKeyboard.sendKeyStroke(KEY_C); break; case 68: UsbKeyboard.sendKeyStroke(KEY_D); break; } } } void delayMs(unsigned int ms){ for(int i = 0; i