Light_and_Temp_Control
main.cpp
- Committer:
- fedeedlp
- Date:
- 2014-08-07
- Revision:
- 0:8fa77db93e75
File content as of revision 0:8fa77db93e75:
/*This program monitoring the light and the temperature and send a serial command (if the user chose it) and turn on a light signal*/ #include "mbed.h" #include "Servo.h" Servo Servo_Temp(D13); Servo Servo_Light(D14); AnalogIn temperature(A0); AnalogIn light(A1); DigitalOut temp_alert(D0); DigitalOut light_alert(D1); int i; Serial pc(USBTX, USBRX); // tx, rx int main() { temp_alert=0; light_alert=0; pc.printf("Press 'y' to receive commands or 'n' for not receive\n"); char mode = pc.getc(); while(1) { if (temperature>5) { //High Temperature i=0; while(i<10) { temp_alert=1; wait(1); temp_alert=0; i++; } temp_alert=1; Servo_Temp.position(0); if(mode=='y') pc.printf("High Temperature"); } else temp_alert=0; Servo_Temp.position(100); if (light<1) { //Low Light i=0; while(i<10) { light_alert=1; wait(1); light_alert=0; i++; } light_alert=1; Servo_Light.position(0); if(mode=='y') pc.printf("Low Light"); } else light_alert=0; Servo_Light.position(100); wait(1); } }