Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: usb_device/main.cpp
- Revision:
- 0:6a73d3dc037e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usb_device/main.cpp Mon Jul 28 20:29:28 2014 +0000
@@ -0,0 +1,42 @@
+// USB Device demo - control mouse pointer with buttons
+
+#include "mbed.h"
+#include "USBMouse.h"
+
+// USB Mouse object
+USBMouse mouse;
+
+// Define buttons
+DigitalIn button_up(p5);
+DigitalIn button_down(p6);
+DigitalIn button_left(p7);
+DigitalIn button_right(p8);
+
+DigitalOut myled(LED1);
+
+int main() {
+ int x = 0;
+ int y = 0;
+
+
+ while (1) {
+
+ // Determine mouse pointer horizontal direction
+ x = button_left ^ button_right;
+ if ( button_right ) {
+ x = -1 * x;
+ }
+
+ // Determine mouse pointer vertical direction
+ y = button_up ^ button_down;
+ if ( button_down ) {
+ y = -1 * y;
+ }
+
+ // Move mouse
+ mouse.move(x, y);
+
+ // Wait for next cycle
+ wait(0.001);
+ }
+}
\ No newline at end of file