mbed Starter Kit / mbed Starter Kit Demo Programs
Committer:
ShawnHymel
Date:
Mon Jul 28 20:29:28 2014 +0000
Revision:
0:6a73d3dc037e
Added main.cpp files from each of the demo programs. Libraries are not included.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ShawnHymel 0:6a73d3dc037e 1 // USB Device demo - control mouse pointer with buttons
ShawnHymel 0:6a73d3dc037e 2
ShawnHymel 0:6a73d3dc037e 3 #include "mbed.h"
ShawnHymel 0:6a73d3dc037e 4 #include "USBMouse.h"
ShawnHymel 0:6a73d3dc037e 5
ShawnHymel 0:6a73d3dc037e 6 // USB Mouse object
ShawnHymel 0:6a73d3dc037e 7 USBMouse mouse;
ShawnHymel 0:6a73d3dc037e 8
ShawnHymel 0:6a73d3dc037e 9 // Define buttons
ShawnHymel 0:6a73d3dc037e 10 DigitalIn button_up(p5);
ShawnHymel 0:6a73d3dc037e 11 DigitalIn button_down(p6);
ShawnHymel 0:6a73d3dc037e 12 DigitalIn button_left(p7);
ShawnHymel 0:6a73d3dc037e 13 DigitalIn button_right(p8);
ShawnHymel 0:6a73d3dc037e 14
ShawnHymel 0:6a73d3dc037e 15 DigitalOut myled(LED1);
ShawnHymel 0:6a73d3dc037e 16
ShawnHymel 0:6a73d3dc037e 17 int main() {
ShawnHymel 0:6a73d3dc037e 18 int x = 0;
ShawnHymel 0:6a73d3dc037e 19 int y = 0;
ShawnHymel 0:6a73d3dc037e 20
ShawnHymel 0:6a73d3dc037e 21
ShawnHymel 0:6a73d3dc037e 22 while (1) {
ShawnHymel 0:6a73d3dc037e 23
ShawnHymel 0:6a73d3dc037e 24 // Determine mouse pointer horizontal direction
ShawnHymel 0:6a73d3dc037e 25 x = button_left ^ button_right;
ShawnHymel 0:6a73d3dc037e 26 if ( button_right ) {
ShawnHymel 0:6a73d3dc037e 27 x = -1 * x;
ShawnHymel 0:6a73d3dc037e 28 }
ShawnHymel 0:6a73d3dc037e 29
ShawnHymel 0:6a73d3dc037e 30 // Determine mouse pointer vertical direction
ShawnHymel 0:6a73d3dc037e 31 y = button_up ^ button_down;
ShawnHymel 0:6a73d3dc037e 32 if ( button_down ) {
ShawnHymel 0:6a73d3dc037e 33 y = -1 * y;
ShawnHymel 0:6a73d3dc037e 34 }
ShawnHymel 0:6a73d3dc037e 35
ShawnHymel 0:6a73d3dc037e 36 // Move mouse
ShawnHymel 0:6a73d3dc037e 37 mouse.move(x, y);
ShawnHymel 0:6a73d3dc037e 38
ShawnHymel 0:6a73d3dc037e 39 // Wait for next cycle
ShawnHymel 0:6a73d3dc037e 40 wait(0.001);
ShawnHymel 0:6a73d3dc037e 41 }
ShawnHymel 0:6a73d3dc037e 42 }