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.
Dependencies: C12832_lcd DebounceInterrupts USBDevice mbed
Fork of USBAbsoluteMouse by
main.cpp@4:42fa048620b3, 2014-03-27 (annotated)
- Committer:
- bhakti08
- Date:
- Thu Mar 27 19:04:33 2014 +0000
- Revision:
- 4:42fa048620b3
- Parent:
- 3:976579c5ba99
Modified to add comments
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bhakti08 | 4:42fa048620b3 | 1 | /*****************************************************************************/ |
| bhakti08 | 4:42fa048620b3 | 2 | /*Function: This program is used to emulate a USB Mouse. The mouse position */ |
| bhakti08 | 4:42fa048620b3 | 3 | /* can be changed by the potentiometers. The output values of x and */ |
| bhakti08 | 4:42fa048620b3 | 4 | /* y are modified to move the bubble on the LCD on another MBED */ |
| bhakti08 | 4:42fa048620b3 | 5 | /* acting as USB Host. The program for MBED USB Host can be found at*/ |
| bhakti08 | 4:42fa048620b3 | 6 | /* http://mbed.org/users/bhakti08/code/USB_Project_Host/ */ |
| bhakti08 | 4:42fa048620b3 | 7 | /*Author: Bhakti Kulkarni */ |
| bhakti08 | 4:42fa048620b3 | 8 | /*Date: 03/27/2014 */ |
| bhakti08 | 4:42fa048620b3 | 9 | /*****************************************************************************/ |
| AdamGreen | 0:b2c327d045a2 | 10 | #include <mbed.h> |
| AdamGreen | 0:b2c327d045a2 | 11 | #include <USBMouse.h> |
| bhakti08 | 3:976579c5ba99 | 12 | #include "DebouncedIn.h" |
| bhakti08 | 3:976579c5ba99 | 13 | #include "C12832_lcd.h" |
| bhakti08 | 3:976579c5ba99 | 14 | #include "DebouncedInterrupt.h" |
| AdamGreen | 0:b2c327d045a2 | 15 | |
| bhakti08 | 3:976579c5ba99 | 16 | #define RANGE 0.02 |
| bhakti08 | 3:976579c5ba99 | 17 | #define INTERRUPT |
| bhakti08 | 4:42fa048620b3 | 18 | #define X_MAX 120 |
| bhakti08 | 4:42fa048620b3 | 19 | #define Y_MAX 28 |
| bhakti08 | 4:42fa048620b3 | 20 | #define x_move 7 |
| bhakti08 | 4:42fa048620b3 | 21 | #define y_move 3 |
| bhakti08 | 3:976579c5ba99 | 22 | |
| bhakti08 | 3:976579c5ba99 | 23 | Serial pc(USBTX,USBRX); |
| bhakti08 | 3:976579c5ba99 | 24 | |
| bhakti08 | 4:42fa048620b3 | 25 | DebouncedIn right_click(p13); //Button enulating right click |
| bhakti08 | 4:42fa048620b3 | 26 | DebouncedIn left_click(p16); //Button emulating left click |
| bhakti08 | 4:42fa048620b3 | 27 | DebouncedIn wheel(p14); //Button emulating the wheel button |
| bhakti08 | 3:976579c5ba99 | 28 | C12832_LCD lcd; |
| bhakti08 | 4:42fa048620b3 | 29 | AnalogIn X_in(p20); //Analog input to move bubble in x position |
| bhakti08 | 4:42fa048620b3 | 30 | AnalogIn Y_in(p19); //Analog input to move bubble in y position |
| bhakti08 | 4:42fa048620b3 | 31 | |
| bhakti08 | 4:42fa048620b3 | 32 | USBMouse Mouse; |
| AdamGreen | 0:b2c327d045a2 | 33 | |
| bhakti08 | 3:976579c5ba99 | 34 | int Xpos = 0; |
| bhakti08 | 3:976579c5ba99 | 35 | int Ypos = 0; |
| bhakti08 | 4:42fa048620b3 | 36 | |
| bhakti08 | 4:42fa048620b3 | 37 | /*****************************************************************************/ |
| bhakti08 | 4:42fa048620b3 | 38 | /*This is the main program. This reads the input from the potentiometers, */ |
| bhakti08 | 4:42fa048620b3 | 39 | /*converts them into the values that are required for the lcd display */ |
| bhakti08 | 4:42fa048620b3 | 40 | /*and then sends them as the mouse outputs. */ |
| bhakti08 | 4:42fa048620b3 | 41 | /*****************************************************************************/ |
| bhakti08 | 4:42fa048620b3 | 42 | int main() |
| bhakti08 | 3:976579c5ba99 | 43 | { |
| bhakti08 | 3:976579c5ba99 | 44 | float AinX_old = 0; |
| bhakti08 | 3:976579c5ba99 | 45 | float AinX_new; |
| bhakti08 | 3:976579c5ba99 | 46 | float AinY_old = 0; |
| bhakti08 | 3:976579c5ba99 | 47 | float AinY_new; |
| bhakti08 | 3:976579c5ba99 | 48 | while (true){ |
| bhakti08 | 3:976579c5ba99 | 49 | if(left_click) |
| bhakti08 | 3:976579c5ba99 | 50 | { |
| bhakti08 | 4:42fa048620b3 | 51 | Mouse.click(MOUSE_LEFT); //if left click is pressed, |
| bhakti08 | 4:42fa048620b3 | 52 | // emulate mouse left |
| bhakti08 | 3:976579c5ba99 | 53 | } |
| bhakti08 | 3:976579c5ba99 | 54 | if (right_click) |
| bhakti08 | 3:976579c5ba99 | 55 | { |
| bhakti08 | 4:42fa048620b3 | 56 | Mouse.click(MOUSE_RIGHT); //if right click is pressed, |
| bhakti08 | 4:42fa048620b3 | 57 | // emulate mouse right |
| bhakti08 | 4:42fa048620b3 | 58 | } |
| bhakti08 | 4:42fa048620b3 | 59 | if (wheel) |
| bhakti08 | 4:42fa048620b3 | 60 | { |
| bhakti08 | 4:42fa048620b3 | 61 | Mouse.click(MOUSE_MIDDLE); //if wheel button is pressed, |
| bhakti08 | 4:42fa048620b3 | 62 | // emulate wheel button pressed |
| bhakti08 | 3:976579c5ba99 | 63 | } |
| bhakti08 | 3:976579c5ba99 | 64 | AinX_new = X_in.read(); |
| bhakti08 | 4:42fa048620b3 | 65 | //check if the values are between the LCD values |
| bhakti08 | 4:42fa048620b3 | 66 | if (AinX_new >= AinX_old + RANGE){ |
| bhakti08 | 4:42fa048620b3 | 67 | if (Xpos < X_MAX) |
| bhakti08 | 4:42fa048620b3 | 68 | Xpos += x_move; |
| bhakti08 | 3:976579c5ba99 | 69 | else |
| bhakti08 | 3:976579c5ba99 | 70 | Xpos = Xpos; |
| bhakti08 | 3:976579c5ba99 | 71 | AinX_old = AinX_new; |
| bhakti08 | 3:976579c5ba99 | 72 | } |
| bhakti08 | 3:976579c5ba99 | 73 | else if (AinX_new < AinX_old - RANGE){ |
| bhakti08 | 3:976579c5ba99 | 74 | if (Xpos > 0) |
| bhakti08 | 4:42fa048620b3 | 75 | Xpos -= x_move; |
| bhakti08 | 3:976579c5ba99 | 76 | else |
| bhakti08 | 3:976579c5ba99 | 77 | Xpos = Xpos; |
| bhakti08 | 3:976579c5ba99 | 78 | AinX_old = AinX_new; |
| bhakti08 | 3:976579c5ba99 | 79 | } |
| bhakti08 | 3:976579c5ba99 | 80 | else |
| bhakti08 | 3:976579c5ba99 | 81 | Xpos = Xpos; |
| bhakti08 | 3:976579c5ba99 | 82 | |
| bhakti08 | 3:976579c5ba99 | 83 | AinY_new = Y_in.read(); |
| bhakti08 | 3:976579c5ba99 | 84 | if (AinY_new >= AinY_old + RANGE){ |
| bhakti08 | 4:42fa048620b3 | 85 | if (Ypos < Y_MAX) |
| bhakti08 | 4:42fa048620b3 | 86 | Ypos += y_move; |
| bhakti08 | 3:976579c5ba99 | 87 | else |
| bhakti08 | 3:976579c5ba99 | 88 | Ypos = Ypos; |
| bhakti08 | 3:976579c5ba99 | 89 | AinY_old = AinY_new; |
| bhakti08 | 3:976579c5ba99 | 90 | } |
| bhakti08 | 3:976579c5ba99 | 91 | else if (AinY_new < AinY_old - RANGE){ |
| bhakti08 | 3:976579c5ba99 | 92 | if (Ypos > 0) |
| bhakti08 | 4:42fa048620b3 | 93 | Ypos -= y_move; |
| bhakti08 | 3:976579c5ba99 | 94 | else |
| bhakti08 | 3:976579c5ba99 | 95 | Ypos = Ypos; |
| bhakti08 | 3:976579c5ba99 | 96 | AinY_old = AinY_new; |
| bhakti08 | 3:976579c5ba99 | 97 | } |
| bhakti08 | 3:976579c5ba99 | 98 | else |
| bhakti08 | 3:976579c5ba99 | 99 | Ypos = Ypos; |
| bhakti08 | 4:42fa048620b3 | 100 | Mouse.move(Xpos,Ypos); //Send the values as the mouse output |
| AdamGreen | 0:b2c327d045a2 | 101 | } |
| bhakti08 | 4:42fa048620b3 | 102 | } |
| bhakti08 | 4:42fa048620b3 | 103 | |
| bhakti08 | 4:42fa048620b3 | 104 | /*****************************************************************************/ |
