![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Coursework
Diff: main.cpp
- Revision:
- 14:2eddfd5fc1ce
- Parent:
- 13:034ffa96643d
diff -r 034ffa96643d -r 2eddfd5fc1ce main.cpp --- a/main.cpp Sat Jan 08 23:26:11 2022 +0000 +++ b/main.cpp Thu Jan 13 19:18:40 2022 +0000 @@ -4,7 +4,6 @@ #include "hcsr04.h" #include "Piezo.h" #include "string" -#include "PinDetect.h" // FSM Menu // defines directions as 0/1. Note UPPERCASE #define UP 0 @@ -23,9 +22,7 @@ HCSR04 sensor(D14, D15); Piezo Buzzer(PTC10); //Bringing in buttons -//InterruptIn buttonA(PTB9); -PinDetect buttonA(PTB9, PullDown ); - +InterruptIn buttonA(PTB9); InterruptIn buttonB(PTD0); InterruptIn buttonX(PTC17); InterruptIn buttonY(PTC12); @@ -109,12 +106,12 @@ joystick.init(); Timer t; t.start(); - buttonA.setSampleFrequency(20); + // create a thread that'll run the event queue's dispatch function Thread eventThread; eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); - buttonA.attach_asserted(&buttonA_isr); // This is used to call the function putting it in queue allowing the screen toupdat no muxt error + buttonA.rise(queue.event(&buttonA_isr)); // This is used to call the function putting it in queue allowing the screen toupdat no muxt error buttonB.rise(queue.event(&buttonB_isr)); buttonX.rise(queue.event(&buttonX_isr)); buttonY.rise(queue.event(&buttonY_isr)); @@ -126,7 +123,7 @@ lcd.init(); // Button A is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister - // buttonA.mode(PullDown); + buttonA.mode(PullDown); // Button B is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister buttonB.mode(PullDown); // Button X is connected between the pin and 3.3 V, we therefore need to turn on the internal pull-down resister @@ -308,8 +305,9 @@ } } int Presscount(){ - int currenttime; - int lasttime; + int currentTimer; + int lastTimer; + if(currentTimer Press++;