From e7b6591bc5e11cb650c424a0820b5240842f3bc9 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 19 Sep 2015 16:46:34 +0200 Subject: [PATCH] Added Mouse example --- examples/ImprovedMouse/ImprovedMouse.ino | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 examples/ImprovedMouse/ImprovedMouse.ino diff --git a/examples/ImprovedMouse/ImprovedMouse.ino b/examples/ImprovedMouse/ImprovedMouse.ino new file mode 100644 index 0000000..5ccdb96 --- /dev/null +++ b/examples/ImprovedMouse/ImprovedMouse.ino @@ -0,0 +1,65 @@ +/* + Copyright (c) 2014-2015 NicoHood + See the readme for credit to other people. + + Mouse example + Press a button to click or move the mouse. + + See HID Project documentation for more Information. + https://github.com/NicoHood/HID/wiki/Mouse-API +*/ + +#include "HID-Project.h" + +const int pinLed = LED_BUILTIN; +const int pinButtonClick = 2; +const int pinButtonMove = 3; +const int pinButtonScroll = 4; + +void setup() { + // Prepare led + buttons + pinMode(pinLed, OUTPUT); + pinMode(pinButtonClick, INPUT_PULLUP); + pinMode(pinButtonMove, INPUT_PULLUP); + pinMode(pinButtonScroll, INPUT_PULLUP); + + // Sends a clean report to the host. This is important on any Arduino type. + Mouse.begin(); +} + +void loop() { + if (!digitalRead(pinButtonClick)) { + digitalWrite(pinLed, HIGH); + + // Same use as the official library, pretty much self explaining + Mouse.click(); + //Mouse.click(MOUSE_RIGHT); + + // Simple debounce + delay(300); + digitalWrite(pinLed, LOW); + } + + if (!digitalRead(pinButtonMove)) { + digitalWrite(pinLed, HIGH); + + // Same use as the official library, pretty much self explaining + Mouse.move(100, 0); + + // Simple debounce + delay(300); + digitalWrite(pinLed, LOW); + } + + if (!digitalRead(pinButtonScroll)) { + digitalWrite(pinLed, HIGH); + + // Scroll down a bit, make sure the value is high enough + Mouse.move(0, 0, 160); + + // simple debounce + delay(300); + digitalWrite(pinLed, LOW); + } +} +