Salve a tutti, vorrei costruire un pannello con un pro micro che emuli solo alcuni tasti della tastiera (una quindicina).
esiste un codice tipo: pin d1 = tasto
già pronto per essere configurato?
grazie
Salve a tutti, vorrei costruire un pannello con un pro micro che emuli solo alcuni tasti della tastiera (una quindicina).
esiste un codice tipo: pin d1 = tasto
già pronto per essere configurato?
grazie
Mah ... probabilmente cercando con Google qualche esempio ti viene fuori ...
... in fin dei conti devi fare la scansione di una serie di pin e, in funzione del tasto premuto, inviare sulla USB il relativo codice keyboard ...
Guglielmo
ne ho trovato uno ma il codice è per arduino normale e non sono capace a programmare, per questo chiedevo
Riesci a postarlo?
Possibilmente secono i "Sacri Crismi"?
#include <Keyboard.h>
int buttonPin = 2; // Set a button to any pin
void setup()
{
pinMode(buttonPin, INPUT); // Set the button as an input
digitalWrite(buttonPin, HIGH); // Pull the button high
}
void loop()
{
if (digitalRead(buttonPin) == 0) // if the button goes low
{
Keyboard.write('z'); // send a 'z' to the computer via Keyboard HID
delay(1000); // delay so there aren't a kajillion z's
}
}
tra l'altro ho provato a sostituire keyboard.write z con il tasto esc tramite KEY_ESC e mi da errore, cosa da non poco conto dato che molti dei tasti che dovrei utilizzare non sono lettere
Prova invece a guardare QUESTO esempio che ti fa vedere come esattamente si deve fare ...
Guglielmo
è proprio quello che cercavo, il problema è che se faccio copia incolla anche solo per un pulsante aggiuntivo, arduino ide mi da errore e non capisco se sono io che sbaglio o l'esempio è programmato solo per un solo pulsante
Mostra quello che fai partendo da quel programma ...
Guglielmo
allora, in pratica per riuscire a non avere errori ho modificato un po il codice, il problema è che se lo carico sul micro, esegue i comandi in automatico. ecco il codice
#include <Keyboard.h>
void setup()
{
Keyboard.begin();
}
void loop()
{
if(digitalRead(0) == HIGH)
Keyboard.press(KEY_ESC); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(1) == HIGH)
Keyboard.press(KEY_RETURN); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(2) == HIGH)
Keyboard.press(KEY_PAGE_UP); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(3) == HIGH)
Keyboard.press(KEY_PAGE_DOWN); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(4) == HIGH)
Keyboard.press(KEY_KP_PLUS); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(5) == HIGH)
Keyboard.press(KEY_KP_MINUS); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(6) == HIGH)
Keyboard.press(KEY_UP_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(7) == HIGH)
Keyboard.press(KEY_DOWN_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(8) == HIGH)
Keyboard.press(KEY_LEFT_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(9) == HIGH)
Keyboard.press(KEY_RIGHT_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(10) == HIGH)
Keyboard.press(1); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(14) == HIGH)
Keyboard.press(2); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(15) == HIGH)
Keyboard.press(3); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(16) == HIGH)
Keyboard.press(4); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(18) == HIGH)
Keyboard.press(KEY_LEFT_ALT); // Press and hold the Windows key.
Keyboard.press(KEY_F4); // Press and hold the 'r' key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(19) == HIGH)
Keyboard.press(KEY_LEFT_ALT); // Press and hold the Windows key.
Keyboard.press(KEY_TAB); // Press and hold the 'r' key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(20) == HIGH)
Keyboard.press(KEY_LEFT_GUI); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
if(digitalRead(21) == HIGH)
Keyboard.press("z"); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
Keyboard.print("extra"); // Type "Notepad".
}
Guarda che NON stai programmando in Python ...
... studia la sintassi del IF e l'uso delle parentesi graffe.
Guglielmo
ripeto, non sono capace a programmare, ogni volta che modifico qualcosa, mi da errore
E quindi, esattamente la richiesta quale sarebbe?
il problema è che se lo carico sul micro, esegue i comandi in automatico.
come posso risolvere?
Mmmm ... ma lo hai letto il punto 16.1 del REGOLAMENTO ?
16.1
Tenete sempre presente che qui sul forum nessuno scrive software per conto terzi o realizza schemi su ordinazione, ma si aiuta chi viene qui a correggere/ottimizzare il software che lui scrive o gli schemi che lui realizza.Se non si è mai sviluppato su Arduino, si può cominciare con lo studiarsi QUESTO pdf, leggere QUEST'ALTRO , seguire i link indicati in QUESTO post e magari comprare un buon libro (es. QUESTO ).
Quindi, le indicazioni per risolvere le hai avute (mio post #12), noi qui NON scriviamo codice, ma aiutiamo a correggere gli errori e diamo delle indicazioni ... dato che ti mancano proprio le BASI, ti suggerisco i due pdf indicati e, magari, anche l'acquisto e lo studio del libro specificato (che è fatto molto bene).
Purtroppo, come più volte dico, NON basta saper fare copia incolla, con quello si arriva si e no a far lampeggiare un LED, per cose più complesse ... bisogna studiare
Guglielmo
infatti ho pubblicato il codice che ha bisogno di una correzione per funzionare, non vi ho chiesto di scrivermi tutto lo sketch
comunque le indicazioni che mi hai fornito, funzionano con un pulsante solo, con piu pulsanti da errore nella compilazione.
comunque lasciamo perdere, cercherò qualcuno che possa aiutarmi altrove.
saluti
... ma te l'ho data (post #12)!
Hai sbagliato le modifiche ed evidentemente NON conosci la sintassi ne dell'IF ne dell'uso delle parentesi graffe (che, infatti, non hai messo).
Guglielmo
le ho messe ma non cambia nulla
... io nel codice NON le vedo
Guglielmo
lo ricarico com'è in questo momento
#include <Keyboard.h>
void setup()
{
Keyboard.begin();
}
void loop()
{
{pinMode(0, INPUT_PULLUP);
if(digitalRead(0) == HIGH)
Keyboard.press(KEY_ESC); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(1, INPUT_PULLUP);
if(digitalRead(1) == HIGH)
Keyboard.press(KEY_RETURN); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(2, INPUT_PULLUP);
if(digitalRead(2) == HIGH)
Keyboard.press(KEY_PAGE_UP); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(3, INPUT_PULLUP);
if(digitalRead(3) == HIGH)
Keyboard.press(KEY_PAGE_DOWN); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(4, INPUT_PULLUP);
if(digitalRead(4) == HIGH)
Keyboard.press(KEY_KP_PLUS); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(5, INPUT_PULLUP);
if(digitalRead(5) == HIGH)
Keyboard.press(KEY_KP_MINUS); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(6, INPUT_PULLUP);
if(digitalRead(6) == HIGH)
Keyboard.press(KEY_UP_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(7, INPUT_PULLUP);
if(digitalRead(7) == HIGH)
Keyboard.press(KEY_DOWN_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(8, INPUT_PULLUP);
if(digitalRead(8) == HIGH)
Keyboard.press(KEY_LEFT_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(9, INPUT_PULLUP);
if(digitalRead(9) == HIGH)
Keyboard.press(KEY_RIGHT_ARROW); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(10, INPUT_PULLUP);
if(digitalRead(10) == HIGH)
Keyboard.press('1'); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(14, INPUT_PULLUP);
if(digitalRead(14) == HIGH)
Keyboard.press('2'); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(15, INPUT_PULLUP);
if(digitalRead(15) == HIGH)
Keyboard.press('3'); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(16, INPUT_PULLUP);
if(digitalRead(16) == HIGH)
Keyboard.press('4'); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(18, INPUT_PULLUP);
if(digitalRead(18) == HIGH)
Keyboard.press(KEY_LEFT_ALT); // Press and hold the Windows key.
Keyboard.press(KEY_F4); // Press and hold the 'r' key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(19, INPUT_PULLUP);
if(digitalRead(19) == HIGH)
Keyboard.press(KEY_LEFT_ALT); // Press and hold the Windows key.
Keyboard.press(KEY_TAB); // Press and hold the 'r' key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(20, INPUT_PULLUP);
if(digitalRead(20) == HIGH)
Keyboard.press(KEY_LEFT_GUI); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
}
{pinMode(21, INPUT_PULLUP);
if(digitalRead(21) == HIGH)
Keyboard.press('z'); // Press and hold the Windows key.
delay(100); // Wait for the computer to register the press.
Keyboard.print("extra"); // Type "Notepad".
Keyboard.releaseAll(); // Release both of the above keys.
}
}