Tadhg Jones / Mbed 2 deprecated usb_device

Dependencies:   mbed USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // USB Device demo - control mouse pointer with buttons
00002 
00003 #include "mbed.h"
00004 #include "USBMouse.h"
00005 
00006 // USB Mouse object
00007 USBMouse mouse;
00008 
00009 // Define buttons
00010 DigitalIn button_click(p5);
00011 DigitalIn button_scrollup(p6);
00012 DigitalIn button_scrolldown(p7);
00013 
00014 
00015 DigitalOut myled(LED1);
00016 
00017 Timer timer1;
00018 
00019 int main() {
00020     int x;
00021     int y;
00022     int z;
00023     
00024  
00025     while (1) {
00026         y = 1;
00027         z = 1;
00028         x = -1;
00029         
00030 
00031         if ( button_scrolldown ) {
00032             x = 0;
00033         }
00034         
00035         if ( button_click ) {
00036             z = 0;
00037         }
00038         
00039         if ( button_scrollup ) {
00040             y = 0;
00041         }
00042 
00043         // Click mouse
00044         
00045         timer1.start();
00046         if (timer1.read_ms()>=100) {
00047             mouse.click(z); //cliicks
00048             timer1.stop();
00049             timer1.reset();
00050         }
00051         
00052         mouse.scroll(y); //scrolls up
00053         mouse.scroll(x); //scrolls down
00054         
00055         mouse.release(1);
00056 
00057 
00058 
00059         // Wait for next cycle
00060         
00061     }
00062 }