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: mbed
Fork of frdm_Grove_Joystick_Example by
main.cpp@0:2f9598399d00, 2016-01-01 (annotated)
- Committer:
- GregC
- Date:
- Fri Jan 01 16:56:40 2016 +0000
- Revision:
- 0:2f9598399d00
Freedom Seeed Grove Joystick Example
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| GregC | 0:2f9598399d00 | 1 | #include "mbed.h" |
| GregC | 0:2f9598399d00 | 2 | |
| GregC | 0:2f9598399d00 | 3 | AnalogIn xAxis(A0); |
| GregC | 0:2f9598399d00 | 4 | AnalogIn yAxis(A1); |
| GregC | 0:2f9598399d00 | 5 | |
| GregC | 0:2f9598399d00 | 6 | int x,y,button; // global variables to hold values |
| GregC | 0:2f9598399d00 | 7 | Ticker joystick; // recurring interrupt to get joystick data |
| GregC | 0:2f9598399d00 | 8 | |
| GregC | 0:2f9598399d00 | 9 | void joystick_Int_Handler() |
| GregC | 0:2f9598399d00 | 10 | { |
| GregC | 0:2f9598399d00 | 11 | x = xAxis.read() * 1000; // float (0->1) to int (0-1000) |
| GregC | 0:2f9598399d00 | 12 | y = yAxis.read() * 1000; |
| GregC | 0:2f9598399d00 | 13 | if ( (x > 900) || (y > 900) ) |
| GregC | 0:2f9598399d00 | 14 | button = 1; |
| GregC | 0:2f9598399d00 | 15 | else |
| GregC | 0:2f9598399d00 | 16 | button = 0; |
| GregC | 0:2f9598399d00 | 17 | } |
| GregC | 0:2f9598399d00 | 18 | |
| GregC | 0:2f9598399d00 | 19 | int main() |
| GregC | 0:2f9598399d00 | 20 | { |
| GregC | 0:2f9598399d00 | 21 | // init interrupt, call every .2s |
| GregC | 0:2f9598399d00 | 22 | joystick.attach(joystick_Int_Handler,0.2); |
| GregC | 0:2f9598399d00 | 23 | |
| GregC | 0:2f9598399d00 | 24 | // Print out the variables |
| GregC | 0:2f9598399d00 | 25 | while(1){ |
| GregC | 0:2f9598399d00 | 26 | printf("\rX=%3d, Y=%3d, Button=%d",x,y,button); |
| GregC | 0:2f9598399d00 | 27 | } |
| GregC | 0:2f9598399d00 | 28 | } |
