APS de Sistemas Operacionais / Controle 2
Dependencies: mbed-rtos mbed HC_SR04_Ultrasonic_Library
Revision 0:8d53c4c11953, committed 2017-10-21
- Comitter:
- feupos
- Date:
- Sat Oct 21 21:13:13 2017 +0000
- Child:
- 1:c07ed2436cd8
- Commit message:
- initial build
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Oct 21 21:13:13 2017 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "rtos.h"
+
+DigitalOut led1(LED1);
+InterruptIn sw2(SW2);
+uint32_t button_pressed;
+Thread *thread2;
+
+void sw2_press(void)
+{
+ thread2->signal_set(0x1);
+}
+
+void led_thread(void const *argument)
+{
+ while (true) {
+ led1 = !led1;
+ Thread::wait(1000);
+ }
+}
+
+void button_thread(void const *argument)
+{
+ while (true) {
+ Thread::signal_wait(0x1);
+ button_pressed++;
+ }
+}
+
+int main()
+{
+ Thread thread(led_thread);
+ thread2 = new Thread(button_thread);
+
+ button_pressed = 0;
+ sw2.fall(&sw2_press);
+ while (true) {
+ Thread::wait(5000);
+ printf("SW2 was pressed (last 5 seconds): %d \n", button_pressed);
+ fflush(stdout);
+ button_pressed = 0;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sat Oct 21 21:13:13 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Oct 21 21:13:13 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file