![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
prueba1
Dependencies: mbed motoresDC TextLCD SLCD
main.cpp@1:e51f299dd462, 2020-06-23 (annotated)
- Committer:
- 20172573063
- Date:
- Tue Jun 23 23:19:20 2020 +0000
- Revision:
- 1:e51f299dd462
- Parent:
- 0:465ff75162d5
pruebamotor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
20172573063 | 0:465ff75162d5 | 1 | #include "mbed.h" |
20172573063 | 0:465ff75162d5 | 2 | #include "rtos.h" |
20172573063 | 0:465ff75162d5 | 3 | #include "motoresDC.h" |
20172573063 | 1:e51f299dd462 | 4 | #include "TextLCD.h" |
20172573063 | 1:e51f299dd462 | 5 | #include "SLCD.h" |
20172573063 | 0:465ff75162d5 | 6 | |
20172573063 | 0:465ff75162d5 | 7 | |
20172573063 | 1:e51f299dd462 | 8 | InterruptIn botoncito(D12); |
20172573063 | 1:e51f299dd462 | 9 | InterruptIn botonsote(D13); |
20172573063 | 0:465ff75162d5 | 10 | MotoresDC carro(D8,D10, D11, D9, D12, D13); |
20172573063 | 1:e51f299dd462 | 11 | I2C i2c_lcd(D7,D6); |
20172573063 | 1:e51f299dd462 | 12 | TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); |
20172573063 | 1:e51f299dd462 | 13 | Serial pc(USBTX,USBRX); |
20172573063 | 0:465ff75162d5 | 14 | |
20172573063 | 1:e51f299dd462 | 15 | int pulso=0,pulso1=0,num; |
20172573063 | 0:465ff75162d5 | 16 | |
20172573063 | 0:465ff75162d5 | 17 | Thread thread; |
20172573063 | 0:465ff75162d5 | 18 | Thread thread1; |
20172573063 | 0:465ff75162d5 | 19 | Thread thread2; |
20172573063 | 1:e51f299dd462 | 20 | Thread thread3; |
20172573063 | 1:e51f299dd462 | 21 | Thread thread4; |
20172573063 | 0:465ff75162d5 | 22 | |
20172573063 | 1:e51f299dd462 | 23 | DigitalOut gpo(D0); |
20172573063 | 1:e51f299dd462 | 24 | SLCD slcd; |
20172573063 | 1:e51f299dd462 | 25 | |
20172573063 | 1:e51f299dd462 | 26 | void pantallalcd() |
20172573063 | 1:e51f299dd462 | 27 | { |
20172573063 | 1:e51f299dd462 | 28 | lcd.setMode(TextLCD::DispOn); |
20172573063 | 1:e51f299dd462 | 29 | lcd.setBacklight(TextLCD::LightOn); |
20172573063 | 1:e51f299dd462 | 30 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
20172573063 | 1:e51f299dd462 | 31 | } |
20172573063 | 1:e51f299dd462 | 32 | void temp_hora() |
20172573063 | 1:e51f299dd462 | 33 | { |
20172573063 | 1:e51f299dd462 | 34 | set_time(1591802062-18000); |
20172573063 | 1:e51f299dd462 | 35 | while (1) { |
20172573063 | 1:e51f299dd462 | 36 | time_t seconds = time(NULL); |
20172573063 | 1:e51f299dd462 | 37 | char buffer[32]; |
20172573063 | 1:e51f299dd462 | 38 | strftime(buffer, 32, "%H:%M:%S ", localtime(&seconds)); |
20172573063 | 1:e51f299dd462 | 39 | lcd.locate(0,1); |
20172573063 | 1:e51f299dd462 | 40 | lcd.printf("%s", buffer); |
20172573063 | 1:e51f299dd462 | 41 | Thread::wait(1000); |
20172573063 | 1:e51f299dd462 | 42 | } |
20172573063 | 1:e51f299dd462 | 43 | } |
20172573063 | 1:e51f299dd462 | 44 | void boton1() |
20172573063 | 1:e51f299dd462 | 45 | { |
20172573063 | 1:e51f299dd462 | 46 | pulso=!pulso; |
20172573063 | 1:e51f299dd462 | 47 | } |
20172573063 | 0:465ff75162d5 | 48 | void motor_ascend() |
20172573063 | 0:465ff75162d5 | 49 | { |
20172573063 | 0:465ff75162d5 | 50 | while(1) { |
20172573063 | 0:465ff75162d5 | 51 | if(pulso==1) { |
20172573063 | 0:465ff75162d5 | 52 | switch(num) { |
20172573063 | 0:465ff75162d5 | 53 | case '1': |
20172573063 | 0:465ff75162d5 | 54 | carro.conducir(0.3); |
20172573063 | 0:465ff75162d5 | 55 | break; |
20172573063 | 0:465ff75162d5 | 56 | case '2': |
20172573063 | 0:465ff75162d5 | 57 | carro.conducir(0.5); |
20172573063 | 0:465ff75162d5 | 58 | break; |
20172573063 | 0:465ff75162d5 | 59 | case '3': |
20172573063 | 0:465ff75162d5 | 60 | carro.conducir(0.7); |
20172573063 | 0:465ff75162d5 | 61 | break; |
20172573063 | 0:465ff75162d5 | 62 | case '4': |
20172573063 | 0:465ff75162d5 | 63 | carro.conducir(1); |
20172573063 | 0:465ff75162d5 | 64 | break; |
20172573063 | 0:465ff75162d5 | 65 | case '5': |
20172573063 | 1:e51f299dd462 | 66 | |
20172573063 | 0:465ff75162d5 | 67 | NVIC_SystemReset (); |
20172573063 | 0:465ff75162d5 | 68 | break; |
20172573063 | 0:465ff75162d5 | 69 | } |
20172573063 | 0:465ff75162d5 | 70 | |
20172573063 | 0:465ff75162d5 | 71 | Thread::wait(50); |
20172573063 | 0:465ff75162d5 | 72 | } |
20172573063 | 0:465ff75162d5 | 73 | } |
20172573063 | 0:465ff75162d5 | 74 | } |
20172573063 | 0:465ff75162d5 | 75 | void motor_descend() |
20172573063 | 0:465ff75162d5 | 76 | { |
20172573063 | 0:465ff75162d5 | 77 | while(1) { |
20172573063 | 0:465ff75162d5 | 78 | if(pulso==1) { |
20172573063 | 0:465ff75162d5 | 79 | switch(num) { |
20172573063 | 0:465ff75162d5 | 80 | case '4': |
20172573063 | 0:465ff75162d5 | 81 | carro.conducir(0.3); |
20172573063 | 0:465ff75162d5 | 82 | break; |
20172573063 | 0:465ff75162d5 | 83 | case '3': |
20172573063 | 0:465ff75162d5 | 84 | carro.conducir(0.5); |
20172573063 | 0:465ff75162d5 | 85 | break; |
20172573063 | 0:465ff75162d5 | 86 | case '2': |
20172573063 | 0:465ff75162d5 | 87 | carro.conducir(0.7); |
20172573063 | 0:465ff75162d5 | 88 | break; |
20172573063 | 0:465ff75162d5 | 89 | case '1': |
20172573063 | 0:465ff75162d5 | 90 | carro.conducir(1); |
20172573063 | 0:465ff75162d5 | 91 | break; |
20172573063 | 0:465ff75162d5 | 92 | case '5': |
20172573063 | 0:465ff75162d5 | 93 | NVIC_SystemReset (); |
20172573063 | 0:465ff75162d5 | 94 | break; |
20172573063 | 0:465ff75162d5 | 95 | } |
20172573063 | 0:465ff75162d5 | 96 | |
20172573063 | 0:465ff75162d5 | 97 | Thread::wait(50); |
20172573063 | 0:465ff75162d5 | 98 | } |
20172573063 | 0:465ff75162d5 | 99 | } |
20172573063 | 0:465ff75162d5 | 100 | } |
20172573063 | 0:465ff75162d5 | 101 | void cambio() |
20172573063 | 0:465ff75162d5 | 102 | { |
20172573063 | 0:465ff75162d5 | 103 | while(1) { |
20172573063 | 0:465ff75162d5 | 104 | if(pulso==1) { |
20172573063 | 0:465ff75162d5 | 105 | if(num==1) { |
20172573063 | 0:465ff75162d5 | 106 | Thread::wait(2000); |
20172573063 | 0:465ff75162d5 | 107 | num++; |
20172573063 | 0:465ff75162d5 | 108 | } |
20172573063 | 0:465ff75162d5 | 109 | if(num==2) { |
20172573063 | 0:465ff75162d5 | 110 | Thread::wait(2000); |
20172573063 | 0:465ff75162d5 | 111 | num++; |
20172573063 | 0:465ff75162d5 | 112 | } |
20172573063 | 0:465ff75162d5 | 113 | if(num==3) { |
20172573063 | 0:465ff75162d5 | 114 | Thread::wait(2000); |
20172573063 | 0:465ff75162d5 | 115 | num++; |
20172573063 | 0:465ff75162d5 | 116 | } |
20172573063 | 0:465ff75162d5 | 117 | |
20172573063 | 0:465ff75162d5 | 118 | if(num==4) { |
20172573063 | 0:465ff75162d5 | 119 | Thread::wait(6000); |
20172573063 | 0:465ff75162d5 | 120 | num++; |
20172573063 | 0:465ff75162d5 | 121 | } |
20172573063 | 0:465ff75162d5 | 122 | |
20172573063 | 0:465ff75162d5 | 123 | } |
20172573063 | 0:465ff75162d5 | 124 | } |
20172573063 | 0:465ff75162d5 | 125 | } |
20172573063 | 1:e51f299dd462 | 126 | int main() |
20172573063 | 1:e51f299dd462 | 127 | { |
20172573063 | 1:e51f299dd462 | 128 | |
20172573063 | 1:e51f299dd462 | 129 | thread.start (cambio); |
20172573063 | 1:e51f299dd462 | 130 | thread1.set_priority (osPriorityNormal1); |
20172573063 | 1:e51f299dd462 | 131 | thread1.start(motor_ascend); |
20172573063 | 1:e51f299dd462 | 132 | thread2.set_priority (osPriorityNormal1); |
20172573063 | 1:e51f299dd462 | 133 | thread2.start(motor_descend); |
20172573063 | 1:e51f299dd462 | 134 | thread3.start ((temp_hora)); |
20172573063 | 1:e51f299dd462 | 135 | thread3.set_priority (osPriorityNormal2); |
20172573063 | 1:e51f299dd462 | 136 | thread4.start((pantallalcd)); |
20172573063 | 1:e51f299dd462 | 137 | thread.join(); |
20172573063 | 1:e51f299dd462 | 138 | botoncito.mode(PullUp); |
20172573063 | 1:e51f299dd462 | 139 | botoncito.fall(&boton1); |
20172573063 | 0:465ff75162d5 | 140 | |
20172573063 | 0:465ff75162d5 | 141 | |
20172573063 | 1:e51f299dd462 | 142 | |
20172573063 | 1:e51f299dd462 | 143 | |
20172573063 | 1:e51f299dd462 | 144 | } |