proyecto prueba ros

Dependencies:   mbed Servo HC-SR04 max6675

Committer:
20172573063
Date:
Mon Jun 08 21:16:50 2020 +0000
Revision:
0:4cce815f7d81
prueba_rtos;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
20172573063 0:4cce815f7d81 1 #include "mbed.h"
20172573063 0:4cce815f7d81 2 #include "HCSR04.h"
20172573063 0:4cce815f7d81 3 #include "rtos.h"
20172573063 0:4cce815f7d81 4 #include "Servo.h"
20172573063 0:4cce815f7d81 5 #include "max6675.h"
20172573063 0:4cce815f7d81 6 #include "TextLCD.h"
20172573063 0:4cce815f7d81 7 BusOut display7Seg(PTC10, PTC7, PTC6, PTC4, PTC0, PTB19, PTB18);
20172573063 0:4cce815f7d81 8 DigitalOut display1(PTC11);
20172573063 0:4cce815f7d81 9 DigitalOut display2(PTC13);
20172573063 0:4cce815f7d81 10
20172573063 0:4cce815f7d81 11 HCSR04 ultrasonido(PTA7,PTA6);
20172573063 0:4cce815f7d81 12 Servo servomotor(PTA13);
20172573063 0:4cce815f7d81 13 TextLCD lcd(D7, D6, 0x4E);
20172573063 0:4cce815f7d81 14 max6675 sensor(D12,D13,D5);
20172573063 0:4cce815f7d81 15 Serial pc(USBTX,USBRX);
20172573063 0:4cce815f7d81 16 Thread thread;
20172573063 0:4cce815f7d81 17 Thread thread1;
20172573063 0:4cce815f7d81 18 Thread thread2;
20172573063 0:4cce815f7d81 19 Thread thread3;
20172573063 0:4cce815f7d81 20
20172573063 0:4cce815f7d81 21 int anodeComun[10] = {
20172573063 0:4cce815f7d81 22 0b0000001, // 0
20172573063 0:4cce815f7d81 23 0b1001111, // 1
20172573063 0:4cce815f7d81 24 0b0010010, // 2
20172573063 0:4cce815f7d81 25 0b0000110, // 3
20172573063 0:4cce815f7d81 26 0b1001100, // 4
20172573063 0:4cce815f7d81 27 0b0100100, // 5
20172573063 0:4cce815f7d81 28 0b0100000, // 6
20172573063 0:4cce815f7d81 29 0b0001111, // 7
20172573063 0:4cce815f7d81 30 0b0000000, // 8
20172573063 0:4cce815f7d81 31 0b0001100, // 9
20172573063 0:4cce815f7d81 32 };
20172573063 0:4cce815f7d81 33
20172573063 0:4cce815f7d81 34 void ultra()
20172573063 0:4cce815f7d81 35 {
20172573063 0:4cce815f7d81 36 while(1) {
20172573063 0:4cce815f7d81 37 float distancia=ultrasonido.getCm();
20172573063 0:4cce815f7d81 38 printf("%2.f\n",distancia);
20172573063 0:4cce815f7d81 39 Thread::wait(1000);
20172573063 0:4cce815f7d81 40 }
20172573063 0:4cce815f7d81 41 }
20172573063 0:4cce815f7d81 42 void servo()
20172573063 0:4cce815f7d81 43 {
20172573063 0:4cce815f7d81 44
20172573063 0:4cce815f7d81 45 servomotor.calibrate(0.001, 180);
20172573063 0:4cce815f7d81 46
20172573063 0:4cce815f7d81 47 while(1) {
20172573063 0:4cce815f7d81 48 for(int i=0; i<100; i++) {
20172573063 0:4cce815f7d81 49 servomotor = i*0.01;
20172573063 0:4cce815f7d81 50 printf("%d",i);
20172573063 0:4cce815f7d81 51 Thread::wait(1000);
20172573063 0:4cce815f7d81 52 }
20172573063 0:4cce815f7d81 53 for(int i=100; i>0; i--) {
20172573063 0:4cce815f7d81 54 servomotor = i*0.01;
20172573063 0:4cce815f7d81 55 printf("%d",i);
20172573063 0:4cce815f7d81 56 Thread::wait(1000);
20172573063 0:4cce815f7d81 57 }
20172573063 0:4cce815f7d81 58 }
20172573063 0:4cce815f7d81 59 }
20172573063 0:4cce815f7d81 60 void temp_hora()
20172573063 0:4cce815f7d81 61 {
20172573063 0:4cce815f7d81 62 set_time(1256729737);
20172573063 0:4cce815f7d81 63 int cf = 0;
20172573063 0:4cce815f7d81 64 while (1) {
20172573063 0:4cce815f7d81 65 time_t seconds = time(NULL);
20172573063 0:4cce815f7d81 66 float temp = sensor.gettemp(cf);
20172573063 0:4cce815f7d81 67 printf("%d", seconds);
20172573063 0:4cce815f7d81 68 printf("Fecha= %s", ctime(&seconds));
20172573063 0:4cce815f7d81 69
20172573063 0:4cce815f7d81 70 char buffer[32];
20172573063 0:4cce815f7d81 71 strftime(buffer, 32, "%H:%M:%S ", localtime(&seconds));
20172573063 0:4cce815f7d81 72 printf("%s", buffer);
20172573063 0:4cce815f7d81 73
20172573063 0:4cce815f7d81 74
20172573063 0:4cce815f7d81 75 if (cf) {
20172573063 0:4cce815f7d81 76 printf("%4.2f%cF \n\033[2K\033[1A",temp,176);
20172573063 0:4cce815f7d81 77 lcd.printf("%4.2f%cF \n\033[2K\033[1A",temp,176);
20172573063 0:4cce815f7d81 78 } else {
20172573063 0:4cce815f7d81 79 printf("%4.2f%cC \n",temp,176);
20172573063 0:4cce815f7d81 80 lcd.printf("%4.2f%cC \n",temp,176);
20172573063 0:4cce815f7d81 81 }
20172573063 0:4cce815f7d81 82
20172573063 0:4cce815f7d81 83
20172573063 0:4cce815f7d81 84 Thread::wait(1000);
20172573063 0:4cce815f7d81 85 }
20172573063 0:4cce815f7d81 86 }
20172573063 0:4cce815f7d81 87 void seg()
20172573063 0:4cce815f7d81 88 {
20172573063 0:4cce815f7d81 89 float distancia=ultrasonido.getCm();
20172573063 0:4cce815f7d81 90 while(1) {
20172573063 0:4cce815f7d81 91 int d,u,n;
20172573063 0:4cce815f7d81 92 n=int(distancia);
20172573063 0:4cce815f7d81 93
20172573063 0:4cce815f7d81 94 d = n /10;
20172573063 0:4cce815f7d81 95 u = n % 10;
20172573063 0:4cce815f7d81 96
20172573063 0:4cce815f7d81 97 display1=1;
20172573063 0:4cce815f7d81 98 display2=0;
20172573063 0:4cce815f7d81 99 display7Seg=anodeComun[d];
20172573063 0:4cce815f7d81 100 Thread::wait(1000);
20172573063 0:4cce815f7d81 101
20172573063 0:4cce815f7d81 102 display1=0;
20172573063 0:4cce815f7d81 103 display2=1;
20172573063 0:4cce815f7d81 104 display7Seg=anodeComun[u];
20172573063 0:4cce815f7d81 105 Thread::wait(1000);
20172573063 0:4cce815f7d81 106 }
20172573063 0:4cce815f7d81 107 }
20172573063 0:4cce815f7d81 108 int main()
20172573063 0:4cce815f7d81 109 {
20172573063 0:4cce815f7d81 110
20172573063 0:4cce815f7d81 111 thread.start((ultra));
20172573063 0:4cce815f7d81 112 thread1.start ((servo));
20172573063 0:4cce815f7d81 113 thread2.start ((temp_hora));
20172573063 0:4cce815f7d81 114 thread3.start ((seg));
20172573063 0:4cce815f7d81 115
20172573063 0:4cce815f7d81 116 }