Brayan Sebastián Cuervo Lancheros / Mbed 2 deprecated proyectoRTOS

Dependencies:   mbed Servo HC-SR04 TextLCD max6675 SLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HCSR04.h"
00003 #include "rtos.h"
00004 #include "Servo.h"
00005 #include "max6675.h"
00006 #include "TextLCD.h"
00007 
00008 #include "SLCD.h"
00009 
00010 
00011 HCSR04 ultrasonido(PTA7,PTA6);
00012 Servo servomotor(PTA13);
00013 I2C i2c_lcd(D7,D6);
00014 TextLCD_I2C lcd(&i2c_lcd, 0x4E,  TextLCD::LCD16x2, TextLCD::HD44780);
00015 max6675 sensor(D12,D13,D5);
00016 Serial pc(USBTX,USBRX);
00017 Thread thread;
00018 Thread thread1;
00019 Thread thread2;
00020 Thread thread3;
00021 Thread thread4;
00022 
00023 DigitalOut gpo(D0);
00024 SLCD slcd;
00025 
00026 void pantallalcd()
00027 {
00028     lcd.setMode(TextLCD::DispOn);
00029     lcd.setBacklight(TextLCD::LightOn);
00030     lcd.setCursor(TextLCD::CurOff_BlkOff);
00031 }
00032 
00033 void temp_hora()
00034 {
00035     set_time(1256729737);
00036     int cf = 0;
00037     while (1) {
00038         time_t seconds = time(NULL);
00039         float temp = sensor.gettemp(cf);
00040         printf("%d", seconds);
00041         printf("Fecha= %s", ctime(&seconds));
00042 
00043         char buffer[32];
00044         strftime(buffer, 32, "%H:%M:%S   ", localtime(&seconds));
00045         printf("%s", buffer);
00046 
00047         printf("%4.2f%cF \n\033[2K\033[1A",temp,176);
00048         lcd.locate(0,0);
00049         lcd.printf("temp:%1.2f\n",temp);
00050 
00051         Thread::wait(1000);
00052     }
00053 }
00054 
00055 void servo()
00056 {
00057 
00058     servomotor.calibrate(0.001, 180);
00059 
00060     while(1) {
00061         for(int i=0; i<100; i++) {
00062             servomotor = i*0.01;
00063             printf("%d",i);
00064             Thread::wait(100);
00065         }
00066         for(int i=100; i>0; i--) {
00067             servomotor = i*0.01;
00068             printf("%d",i);
00069             Thread::wait(100);
00070         }
00071     }
00072 }
00073 
00074 void ultra()
00075 {
00076     while(1) {
00077         float distancia=ultrasonido.getCm();
00078         lcd.locate(0,1);
00079         lcd.printf("dist:%2.f cm\n",distancia);
00080         Thread::wait(1000);
00081     }
00082 }
00083 void seg()
00084 {
00085     while (true) {
00086         float distancia=ultrasonido.getCm();
00087         slcd.printf("%1.3f",distancia);
00088         Thread::wait(1000);
00089     }
00090 }
00091 
00092 
00093 int main()
00094 {
00095 
00096 
00097     thread.start((ultra));
00098     thread1.start ((servo));
00099     thread2.start ((temp_hora));
00100     thread3.start ((pantallalcd));
00101     thread4.start ((seg));
00102 
00103 }