![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Joystick test for Stage 1 Engineering at the University of York
main.cpp@3:01b95e6267d8, 2021-09-16 (annotated)
- 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?
User | Revision | Line number | New 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 | } |