![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
APS de Sistemas Operacionais / Controle 2
Dependencies: mbed-rtos mbed HC_SR04_Ultrasonic_Library
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "ultrasonic.h" 00004 00005 DigitalOut led1(LED1); 00006 InterruptIn sw2(SW2); 00007 uint32_t button_pressed; 00008 Thread *thread2; 00009 ultrasonic us = ultrasonic(PTC2, PTC3, 100, 1000); 00010 00011 void sw2_press(void) 00012 { 00013 thread2->signal_set(0x1); 00014 00015 } 00016 00017 void led_thread(void const *argument) 00018 { 00019 while (true) { 00020 led1 = !led1; 00021 Thread::wait(1000); 00022 } 00023 } 00024 00025 void button_thread(void const *argument) 00026 { 00027 while (true) { 00028 Thread::signal_wait(0x1); 00029 float x = us.getCurrentDistance(); 00030 printf("distance = %f\n", x); 00031 button_pressed++; 00032 } 00033 } 00034 00035 int main() 00036 { 00037 Thread thread(led_thread); 00038 thread2 = new Thread(button_thread); 00039 //teste 00040 00041 button_pressed = 0; 00042 sw2.fall(&sw2_press); 00043 while (true) { 00044 Thread::wait(5000); 00045 printf("SW2 was pressed (last 5 seconds): %d \n", button_pressed); 00046 fflush(stdout); 00047 button_pressed = 0; 00048 } 00049 }
Generated on Sat Jul 23 2022 18:10:50 by
![doxygen](doxygen.png)