Brayan Sebastián Cuervo Lancheros / Mbed 2 deprecated proyectoprueba3

Dependencies:   mbed Servo HC-SR04 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 BusOut display7Seg(PTC10, PTC7, PTC6, PTC4, PTC0, PTB19, PTB18);
00008 DigitalOut display1(PTC11);
00009 DigitalOut display2(PTC13);
00010 
00011 HCSR04 ultrasonido(PTA7,PTA6);
00012 Servo servomotor(PTA13);
00013 TextLCD lcd(D7, D6, 0x4E);
00014 max6675 sensor(D12,D13,D5);
00015 Serial pc(USBTX,USBRX);
00016 Thread thread;
00017 Thread thread1;
00018 Thread thread2;
00019 Thread thread3;
00020 
00021 int anodeComun[10] = {
00022     0b0000001, // 0
00023     0b1001111, // 1
00024     0b0010010, // 2
00025     0b0000110, // 3
00026     0b1001100, // 4
00027     0b0100100, // 5
00028     0b0100000, // 6
00029     0b0001111, // 7
00030     0b0000000, // 8
00031     0b0001100, // 9
00032 };
00033 
00034 void ultra()
00035 {
00036     while(1) {
00037         float distancia=ultrasonido.getCm();
00038         printf("%2.f\n",distancia);
00039         Thread::wait(1000);
00040     }
00041 }
00042 void servo()
00043 {
00044 
00045     servomotor.calibrate(0.001, 180);
00046 
00047     while(1) {
00048         for(int i=0; i<100; i++) {
00049             servomotor = i*0.01;
00050             printf("%d",i);
00051             Thread::wait(1000);
00052         }
00053         for(int i=100; i>0; i--) {
00054             servomotor = i*0.01;
00055             printf("%d",i);
00056             Thread::wait(1000);
00057         }
00058     }
00059 }
00060 void temp_hora()
00061 {
00062     set_time(1256729737);
00063     int cf = 0;
00064     while (1) {
00065         time_t seconds = time(NULL);
00066         float temp = sensor.gettemp(cf);
00067         printf("%d", seconds);
00068         printf("Fecha= %s", ctime(&seconds));
00069 
00070         char buffer[32];
00071         strftime(buffer, 32, "%H:%M:%S   ", localtime(&seconds));
00072         printf("%s", buffer);
00073 
00074 
00075         if (cf) {
00076             printf("%4.2f%cF \n\033[2K\033[1A",temp,176);
00077             lcd.printf("%4.2f%cF \n\033[2K\033[1A",temp,176);
00078         } else {
00079             printf("%4.2f%cC \n",temp,176);
00080             lcd.printf("%4.2f%cC \n",temp,176);
00081         }
00082 
00083 
00084         Thread::wait(1000);
00085     }
00086 }
00087 void seg()
00088 {
00089     float distancia=ultrasonido.getCm();
00090     while(1) {
00091         int d,u,n;
00092         n=int(distancia);
00093 
00094         d = n /10;
00095         u = n % 10;
00096 
00097         display1=1;
00098         display2=0;
00099         display7Seg=anodeComun[d];
00100         Thread::wait(1000);
00101 
00102         display1=0;
00103         display2=1;
00104         display7Seg=anodeComun[u];
00105         Thread::wait(1000);
00106     }
00107 }
00108 int main()
00109 {
00110  
00111     thread.start((ultra));
00112     thread1.start ((servo));
00113     thread2.start ((temp_hora));
00114     thread3.start ((seg));
00115 
00116 }