prueba1
Dependencies: mbed motoresDC TextLCD SLCD
main.cpp
- Committer:
- 20172573063
- Date:
- 2020-06-23
- Revision:
- 1:e51f299dd462
- Parent:
- 0:465ff75162d5
File content as of revision 1:e51f299dd462:
#include "mbed.h" #include "rtos.h" #include "motoresDC.h" #include "TextLCD.h" #include "SLCD.h" InterruptIn botoncito(D12); InterruptIn botonsote(D13); MotoresDC carro(D8,D10, D11, D9, D12, D13); I2C i2c_lcd(D7,D6); TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); Serial pc(USBTX,USBRX); int pulso=0,pulso1=0,num; Thread thread; Thread thread1; Thread thread2; Thread thread3; Thread thread4; DigitalOut gpo(D0); SLCD slcd; void pantallalcd() { lcd.setMode(TextLCD::DispOn); lcd.setBacklight(TextLCD::LightOn); lcd.setCursor(TextLCD::CurOff_BlkOff); } void temp_hora() { set_time(1591802062-18000); while (1) { time_t seconds = time(NULL); char buffer[32]; strftime(buffer, 32, "%H:%M:%S ", localtime(&seconds)); lcd.locate(0,1); lcd.printf("%s", buffer); Thread::wait(1000); } } void boton1() { pulso=!pulso; } void motor_ascend() { while(1) { if(pulso==1) { switch(num) { case '1': carro.conducir(0.3); break; case '2': carro.conducir(0.5); break; case '3': carro.conducir(0.7); break; case '4': carro.conducir(1); break; case '5': NVIC_SystemReset (); break; } Thread::wait(50); } } } void motor_descend() { while(1) { if(pulso==1) { switch(num) { case '4': carro.conducir(0.3); break; case '3': carro.conducir(0.5); break; case '2': carro.conducir(0.7); break; case '1': carro.conducir(1); break; case '5': NVIC_SystemReset (); break; } Thread::wait(50); } } } void cambio() { while(1) { if(pulso==1) { if(num==1) { Thread::wait(2000); num++; } if(num==2) { Thread::wait(2000); num++; } if(num==3) { Thread::wait(2000); num++; } if(num==4) { Thread::wait(6000); num++; } } } } int main() { thread.start (cambio); thread1.set_priority (osPriorityNormal1); thread1.start(motor_ascend); thread2.set_priority (osPriorityNormal1); thread2.start(motor_descend); thread3.start ((temp_hora)); thread3.set_priority (osPriorityNormal2); thread4.start((pantallalcd)); thread.join(); botoncito.mode(PullUp); botoncito.fall(&boton1); }