Priyank Kalgaonkar
/
TALab3BJoystickECE595
ECE595 - Lab 3 Part 2 - Joystick Program - TA
main.cpp@4:da0f4a1c6416, 2021-01-16 (annotated)
- Committer:
- priyank12p
- Date:
- Sat Jan 16 00:30:23 2021 +0000
- Revision:
- 4:da0f4a1c6416
- Parent:
- 3:b7e534ebe607
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
priyank12p | 0:4cb6e9d0da34 | 1 | #include "mbed.h" |
priyank12p | 4:da0f4a1c6416 | 2 | AnalogIn xAxis(A0); |
priyank12p | 4:da0f4a1c6416 | 3 | AnalogIn yAxis(A1); |
priyank12p | 4:da0f4a1c6416 | 4 | |
priyank12p | 4:da0f4a1c6416 | 5 | int x,y,button; // global variables to hold values |
priyank12p | 4:da0f4a1c6416 | 6 | Ticker joystick; // recurring interrupt to get joystick data |
priyank12p | 1:af23cbc41990 | 7 | |
priyank12p | 4:da0f4a1c6416 | 8 | void joystick_Int_Handler() { |
priyank12p | 4:da0f4a1c6416 | 9 | x = xAxis.read() * 1000; // float (0->1) to int (0-1000) |
priyank12p | 4:da0f4a1c6416 | 10 | y = yAxis.read() * 1000; |
priyank12p | 4:da0f4a1c6416 | 11 | if ( (x > 900) || (y > 900) ) |
priyank12p | 4:da0f4a1c6416 | 12 | button = 1; |
priyank12p | 4:da0f4a1c6416 | 13 | else |
priyank12p | 4:da0f4a1c6416 | 14 | button = 0; |
priyank12p | 4:da0f4a1c6416 | 15 | } |
priyank12p | 4:da0f4a1c6416 | 16 | |
priyank12p | 4:da0f4a1c6416 | 17 | int main () { |
priyank12p | 4:da0f4a1c6416 | 18 | //init interrupt, call every .2s |
priyank12p | 4:da0f4a1c6416 | 19 | joystick.attach(joystick_Int_Handler,0.2); |
priyank12p | 4:da0f4a1c6416 | 20 | |
priyank12p | 4:da0f4a1c6416 | 21 | // Print out the variables |
priyank12p | 4:da0f4a1c6416 | 22 | while(1){ |
priyank12p | 4:da0f4a1c6416 | 23 | printf("\rX=%3d, Y=%3d, Button=%d\n",x,y,button); |
priyank12p | 0:4cb6e9d0da34 | 24 | } |
priyank12p | 1:af23cbc41990 | 25 | } |