Joystick test for Stage 1 Engineering at the University of York

Dependencies:   UoY-serial

Committer:
ajp109
Date:
Thu Sep 16 19:57:31 2021 +0000
Revision:
3:01b95e6267d8
Parent:
2:4dca570013d8
Add mbed_app.json to enable floating-point printf()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ajp109 0:62608d16d10f 1 #include "mbed.h"
ajp109 0:62608d16d10f 2
ajp109 0:62608d16d10f 3 int main()
ajp109 0:62608d16d10f 4 {
ajp109 0:62608d16d10f 5 AnalogIn x(A0);
ajp109 0:62608d16d10f 6 AnalogIn y(A1);
ajp109 0:62608d16d10f 7 DigitalIn button(D2, PullUp);
ajp109 0:62608d16d10f 8
ajp109 0:62608d16d10f 9 // Loop forever...
ajp109 0:62608d16d10f 10 while (true) {
ajp109 0:62608d16d10f 11 // Always print out the X and Y values
ajp109 1:3edadd59e1ef 12 printf("x:%d y:%d\n", x.read_u16(), y.read_u16());
ajp109 0:62608d16d10f 13 if (button == false) {
ajp109 0:62608d16d10f 14 // If the button is being pressed, add a suitable message
ajp109 1:3edadd59e1ef 15 printf("\t(button pressed)\n");
ajp109 0:62608d16d10f 16 }
ajp109 0:62608d16d10f 17 thread_sleep_for(500);
ajp109 0:62608d16d10f 18 }
ajp109 0:62608d16d10f 19 }