Installation et test de la carte : https://www.arduino.cc/en/Guide/ArduinoLeonardoMicro
Clavier (attention avec un clavier sans pavé numérique le « 1 » = »<shift>1″
/*
************ LEONARDO TOUCH ****************
Simultation enter the 1 touch of the keyboard
With a keyboard with Shift combinaison for numbers
The circuit:
– pushbutton attached from pin 4 to +5V
– 10 kilohm resistor attached from pin 4 to groundSee https://www.arduino.cc/en/Reference/KeyboardModifiers
*/
#include « Keyboard.h »
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pinint ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickersvoid setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Keyboard.begin();
digitalWrite(ledPin, ledState);
}void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}if ((millis() – lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState = !ledState;
Keyboard.press(KEY_RIGHT_SHIFT);
Keyboard.print(« 1 »);
Keyboard.release(KEY_RIGHT_SHIFT);
digitalWrite(ledPin, ledState);
}
}
}
lastButtonState = reading;
}
Souris:
#include « Mouse.h »
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
Mouse.begin();
LedBlink(6, 500);
}void LedBlink(int nb, int tempo) {
for (int i= 1 ; i<=nb; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(tempo);
digitalWrite(LED_BUILTIN, LOW);
delay(tempo);
}
}
// the loop function runs over and over again forever
void loop() {
//digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Mouse.move(0, -1);
delay(2000);
Mouse.move(0, 1);
//digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Test du sketch http://arduino.cc/en/Tutorial/KeyboardLogout avec une carte Arduino Leonardo.
1°) Préparation, prévoir un fil à relier de la broche 2 (digitale) à la masse
2°) Raccordement de la carte au PC et déchargement du sketch
3°) Branchement de la carte sur le port USB d’un PC (test sous windows et ubuntu)
4°) Relier le fil de la broche 2 à la masse pour lancer le reboot du pc
Votre commentaire