DIGITALESAVANZADOS

Dependencies:   mbed Servo HC-SR04 TextLCD max6675

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