![](/media/cache/profiles/a36470cf1f8e5aaf38466d65bd080699.jpg.50x50_q85.jpg)
Joystick example
Fork of 1620_App_Board_Pots by
Revision 2:4df3e4788aac, committed 2017-03-01
- Comitter:
- eencae
- Date:
- Wed Mar 01 11:28:59 2017 +0000
- Parent:
- 1:d957f119593e
- Commit message:
- Initial commit.;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d957f119593e -r 4df3e4788aac main.cpp --- a/main.cpp Tue Feb 28 20:23:16 2017 +0000 +++ b/main.cpp Wed Mar 01 11:28:59 2017 +0000 @@ -1,6 +1,6 @@ /* ELEC1620 Application Board Example -Potentiometers +Joystick (c) Dr Craig A. Evans, University of Leeds, Feb 2017 @@ -8,21 +8,24 @@ #include "mbed.h" -AnalogIn pot0(p20); -AnalogIn pot1(p19); -AnalogIn pot2(p17); +// these pins are shared by the potentiometers +AnalogIn joy_v(p20); +AnalogIn joy_h(p19); +AnalogIn joy_button(p17); // could be DigitalIn, but use AnalogIn so pot can also be used int main() { while(1) { - - float pot0_val = pot0.read(); // returns a float in the range 0.0 to 1.0 - //float pot0_val = pot0; // short-hand + + // read each of the pins + float x = joy_h.read(); + float y = joy_v.read(); + float button = joy_button.read(); + + // print over serial + printf("x = %.2f | y = %.2f | button = %.2f\n",x,y,button); - float pot0_voltage = pot0_val*3.3f; // multiply by 3.3 to get the voltage - - printf("Pot 0 val = %.2f (%.2f V)\n",pot0_val,pot0_voltage); - + // small delay between readings wait(0.2); }