David Mc Sherry
/
EMBED_LAB_Q1
Question 1 for Embed Lab
Diff: main.cpp
- Revision:
- 1:780300dcee8d
- Parent:
- 0:0cbd2a7185e7
- Child:
- 2:c82fdcdbcab2
--- a/main.cpp Mon Aug 16 16:47:23 2021 +0000 +++ b/main.cpp Sat Aug 21 09:14:59 2021 +0000 @@ -1,47 +1,59 @@ -#include "mbed.h" + // My first program did not have an interrupt and as a result sometime it would + // display the button twice. this was resolved by the use on an interrupt. + + #include "mbed.h" +Serial pc (USBTX, USBRX); -InterruptIn up (p15); -InterruptIn down (p12); -InterruptIn left (p13); -InterruptIn right (p16); -InterruptIn center (p14); +InterruptIn center(p14); +InterruptIn left(p13); +InterruptIn right(p16); +InterruptIn up(p15); +InterruptIn down(p12); -void Up (){ - - printf("Up\r\n"); - - } - -void Down (){ - - printf("Down\r\n"); - +void center_released() { wait (0.25); +} +void center_pressed() { + pc.printf("center\n\r"); +} +void left_released() { wait (0.25); +} +void left_pressed() { + pc.printf("left\n\r"); +} +void right_released() { wait (0.25); +} +void right_pressed() { + pc.printf("right\n\r"); +} +void up_released() { wait (0.25); +} +void up_pressed() { + pc.printf("up\n\r"); +} +void down_released() { wait (0.25); +} +void down_pressed() { + pc.printf("down\n\r"); +} +int main() { + + // Both rise and fall edges generate an interrupt + center.fall(¢er_released); + center.rise(¢er_pressed); + left.fall(&left_released); + left.rise(&left_pressed); + right.fall(&right_released); + right.rise(&right_pressed); + up.fall(&up_released); + up.rise(&up_pressed); + down.fall(&down_released); + down.rise(&down_pressed); + + left.mode(PullDown); + right.mode(PullDown); + up.mode(PullDown); + down.mode(PullDown); + + while (1) { } - -void Left (){ - - printf("Left\r\n"); - - } - -void Right (){ - - printf("Right\r\n"); - - } - -void Center (){ - - printf("Center\r\n"); - - } - -int main() { - - up.rise (&Up); - down.rise (&Down); - left.rise (&Left); - right.rise (&Right); - center.rise (&Center); - } - +} \ No newline at end of file