basic version
Dependencies: C12832_lcd USBHost mbed
main.cpp
- Committer:
- cathal66
- Date:
- 2015-01-14
- Revision:
- 2:7210303c9115
- Parent:
- 1:ebf16f5cbdec
- Child:
- 3:be269540df58
File content as of revision 2:7210303c9115:
#include "mbed.h" #include "rtos.h" #include "C12832_lcd.h" float sonarDistance; float servoPosition; Mutex sonarDistance_mutex; Mutex servoPosition_mutex; AnalogIn sonarPin(p17); PwmOut servoPin(p21); C12832_LCD lcd; void sonarSensor(void const *args){ while(true){ sonarDistance_mutex.lock(); sonarDistance = sonarPin.read(); sonarDistance_mutex.unlock(); } } void servoControl(void const *args){ while(true){ servoPosition_mutex.lock(); servoPin.write(servoPosition); servoPosition_mutex.unlock(); } } void logic(void const *args){ while(true){ sonarDistance_mutex.lock(); servoPosition_mutex.lock(); servoPosition = sonarDistance; sonarDistance_mutex.unlock(); servoPosition_mutex.unlock(); } } void display(void const *args){ while(true){ sonarDistance_mutex.lock(); servoPosition_mutex.lock(); lcd.cls(); lcd.locate(0,0); lcd.printf("Sonar : %3.2f \nServo : %3.2f",sonarDistance,servoPosition); sonarDistance_mutex.unlock(); servoPosition_mutex.unlock(); Thread::wait(200); } } int main(){ sonarDistance = 0.0f; servoPosition = 0.0f; Thread sonarSensor_thread(sonarSensor); Thread servoControl_thread(servoControl); Thread logic_thread(logic); Thread display_thread(display); while(true){ } }