DIGITALESAVANZADOS
Dependencies: mbed Servo HC-SR04 TextLCD max6675
main.cpp@0:834b339f5f94, 2020-06-09 (annotated)
- Committer:
- juanespitiarobotica
- Date:
- Tue Jun 09 23:50:25 2020 +0000
- Revision:
- 0:834b339f5f94
proyectodertos
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
juanespitiarobotica | 0:834b339f5f94 | 1 | #include "mbed.h" |
juanespitiarobotica | 0:834b339f5f94 | 2 | #include "HCSR04.h" |
juanespitiarobotica | 0:834b339f5f94 | 3 | #include "rtos.h" |
juanespitiarobotica | 0:834b339f5f94 | 4 | #include "Servo.h" |
juanespitiarobotica | 0:834b339f5f94 | 5 | #include "max6675.h" |
juanespitiarobotica | 0:834b339f5f94 | 6 | #include "TextLCD.h" |
juanespitiarobotica | 0:834b339f5f94 | 7 | |
juanespitiarobotica | 0:834b339f5f94 | 8 | HCSR04 ultrasonido(PTA7,PTA6); |
juanespitiarobotica | 0:834b339f5f94 | 9 | Servo servomotor(PTA13); |
juanespitiarobotica | 0:834b339f5f94 | 10 | I2C i2c_lcd(D7,D6); |
juanespitiarobotica | 0:834b339f5f94 | 11 | TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); |
juanespitiarobotica | 0:834b339f5f94 | 12 | max6675 sensor(D12,D13,D5); |
juanespitiarobotica | 0:834b339f5f94 | 13 | Serial pc(USBTX,USBRX); |
juanespitiarobotica | 0:834b339f5f94 | 14 | Thread thread; |
juanespitiarobotica | 0:834b339f5f94 | 15 | Thread thread1; |
juanespitiarobotica | 0:834b339f5f94 | 16 | Thread thread2; |
juanespitiarobotica | 0:834b339f5f94 | 17 | Thread thread3; |
juanespitiarobotica | 0:834b339f5f94 | 18 | |
juanespitiarobotica | 0:834b339f5f94 | 19 | void pantallalcd(){ |
juanespitiarobotica | 0:834b339f5f94 | 20 | lcd.setMode(TextLCD::DispOn); |
juanespitiarobotica | 0:834b339f5f94 | 21 | lcd.setBacklight(TextLCD::LightOn); |
juanespitiarobotica | 0:834b339f5f94 | 22 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
juanespitiarobotica | 0:834b339f5f94 | 23 | } |
juanespitiarobotica | 0:834b339f5f94 | 24 | |
juanespitiarobotica | 0:834b339f5f94 | 25 | void temp_hora() |
juanespitiarobotica | 0:834b339f5f94 | 26 | { |
juanespitiarobotica | 0:834b339f5f94 | 27 | set_time(1256729737); |
juanespitiarobotica | 0:834b339f5f94 | 28 | int cf = 0; |
juanespitiarobotica | 0:834b339f5f94 | 29 | while (1) { |
juanespitiarobotica | 0:834b339f5f94 | 30 | time_t seconds = time(NULL); |
juanespitiarobotica | 0:834b339f5f94 | 31 | float temp = sensor.gettemp(cf); |
juanespitiarobotica | 0:834b339f5f94 | 32 | printf("%d", seconds); |
juanespitiarobotica | 0:834b339f5f94 | 33 | printf("Fecha= %s", ctime(&seconds)); |
juanespitiarobotica | 0:834b339f5f94 | 34 | |
juanespitiarobotica | 0:834b339f5f94 | 35 | char buffer[32]; |
juanespitiarobotica | 0:834b339f5f94 | 36 | strftime(buffer, 32, "%H:%M:%S ", localtime(&seconds)); |
juanespitiarobotica | 0:834b339f5f94 | 37 | printf("%s", buffer); |
juanespitiarobotica | 0:834b339f5f94 | 38 | |
juanespitiarobotica | 0:834b339f5f94 | 39 | printf("%4.2f%cF \n\033[2K\033[1A",temp,176); |
juanespitiarobotica | 0:834b339f5f94 | 40 | lcd.locate(0,0); |
juanespitiarobotica | 0:834b339f5f94 | 41 | lcd.printf("temp:%1.2f\n",temp); |
juanespitiarobotica | 0:834b339f5f94 | 42 | |
juanespitiarobotica | 0:834b339f5f94 | 43 | Thread::wait(1000); |
juanespitiarobotica | 0:834b339f5f94 | 44 | } |
juanespitiarobotica | 0:834b339f5f94 | 45 | } |
juanespitiarobotica | 0:834b339f5f94 | 46 | |
juanespitiarobotica | 0:834b339f5f94 | 47 | void servo() |
juanespitiarobotica | 0:834b339f5f94 | 48 | { |
juanespitiarobotica | 0:834b339f5f94 | 49 | |
juanespitiarobotica | 0:834b339f5f94 | 50 | servomotor.calibrate(0.001, 180); |
juanespitiarobotica | 0:834b339f5f94 | 51 | |
juanespitiarobotica | 0:834b339f5f94 | 52 | while(1) { |
juanespitiarobotica | 0:834b339f5f94 | 53 | for(int i=0; i<100; i++) { |
juanespitiarobotica | 0:834b339f5f94 | 54 | servomotor = i*0.01; |
juanespitiarobotica | 0:834b339f5f94 | 55 | printf("%d",i); |
juanespitiarobotica | 0:834b339f5f94 | 56 | Thread::wait(100); |
juanespitiarobotica | 0:834b339f5f94 | 57 | } |
juanespitiarobotica | 0:834b339f5f94 | 58 | for(int i=100; i>0; i--) { |
juanespitiarobotica | 0:834b339f5f94 | 59 | servomotor = i*0.01; |
juanespitiarobotica | 0:834b339f5f94 | 60 | printf("%d",i); |
juanespitiarobotica | 0:834b339f5f94 | 61 | Thread::wait(100); |
juanespitiarobotica | 0:834b339f5f94 | 62 | } |
juanespitiarobotica | 0:834b339f5f94 | 63 | } |
juanespitiarobotica | 0:834b339f5f94 | 64 | } |
juanespitiarobotica | 0:834b339f5f94 | 65 | |
juanespitiarobotica | 0:834b339f5f94 | 66 | void ultra() |
juanespitiarobotica | 0:834b339f5f94 | 67 | { |
juanespitiarobotica | 0:834b339f5f94 | 68 | while(1) { |
juanespitiarobotica | 0:834b339f5f94 | 69 | float distancia=ultrasonido.getCm(); |
juanespitiarobotica | 0:834b339f5f94 | 70 | lcd.locate(0,1); |
juanespitiarobotica | 0:834b339f5f94 | 71 | lcd.printf("dist:%2.f cm\n",distancia); |
juanespitiarobotica | 0:834b339f5f94 | 72 | Thread::wait(1000); |
juanespitiarobotica | 0:834b339f5f94 | 73 | } |
juanespitiarobotica | 0:834b339f5f94 | 74 | } |
juanespitiarobotica | 0:834b339f5f94 | 75 | |
juanespitiarobotica | 0:834b339f5f94 | 76 | |
juanespitiarobotica | 0:834b339f5f94 | 77 | |
juanespitiarobotica | 0:834b339f5f94 | 78 | int main() |
juanespitiarobotica | 0:834b339f5f94 | 79 | { |
juanespitiarobotica | 0:834b339f5f94 | 80 | |
juanespitiarobotica | 0:834b339f5f94 | 81 | thread.start((ultra)); |
juanespitiarobotica | 0:834b339f5f94 | 82 | thread1.start ((servo)); |
juanespitiarobotica | 0:834b339f5f94 | 83 | thread2.start ((temp_hora)); |
juanespitiarobotica | 0:834b339f5f94 | 84 | thread3.start ((pantallalcd)); |
juanespitiarobotica | 0:834b339f5f94 | 85 | |
juanespitiarobotica | 0:834b339f5f94 | 86 | } |