.

Dependencies:   mbed TextLCD Keypad

Committer:
20161773009
Date:
Mon Mar 09 07:29:01 2020 +0000
Revision:
0:c443bef46896
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
20161773009 0:c443bef46896 1 #include "mbed.h"
20161773009 0:c443bef46896 2 #include "TextLCD.h"
20161773009 0:c443bef46896 3 #include "Keypad.h"
20161773009 0:c443bef46896 4
20161773009 0:c443bef46896 5 PwmOut Md(PTA2)PwmOut Md(PTD4);
20161773009 0:c443bef46896 6 PwmOut Mi(PTA1);
20161773009 0:c443bef46896 7 PwmOut Md(PTD4);
20161773009 0:c443bef46896 8 PwmOut Mi(PTA12);
20161773009 0:c443bef46896 9 TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3,TextLCD::LCD16x2);
20161773009 0:c443bef46896 10 Keypad teclado(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5);
20161773009 0:c443bef46896 11 int d=0, i=0;
20161773009 0:c443bef46896 12 char key; //char porque se recibe de teclado caracteres
20161773009 0:c443bef46896 13 int released=1; //entero que nos dice cuando hay pulso en el teclado
20161773009 0:c443bef46896 14
20161773009 0:c443bef46896 15 void MotorDerecha(){
20161773009 0:c443bef46896 16
20161773009 0:c443bef46896 17 key = teclado.ReadKey();
20161773009 0:c443bef46896 18
20161773009 0:c443bef46896 19 /* if(key == '\0')
20161773009 0:c443bef46896 20 released = 1;
20161773009 0:c443bef46896 21
20161773009 0:c443bef46896 22 if((key != '\0')&&(released == 1) ){*/
20161773009 0:c443bef46896 23 if(key=='A'){
20161773009 0:c443bef46896 24 lcd.cls();
20161773009 0:c443bef46896 25 lcd.locate(0,0);
20161773009 0:c443bef46896 26 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 27 d=1;
20161773009 0:c443bef46896 28 }
20161773009 0:c443bef46896 29 //while (d=1){
20161773009 0:c443bef46896 30 /*if(key==65){
20161773009 0:c443bef46896 31 lcd.cls();
20161773009 0:c443bef46896 32 lcd.locate(0,0);
20161773009 0:c443bef46896 33 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 34
20161773009 0:c443bef46896 35 }
20161773009 0:c443bef46896 36 */
20161773009 0:c443bef46896 37 if(d==1 and key=='0'){
20161773009 0:c443bef46896 38 lcd.cls();
20161773009 0:c443bef46896 39 lcd.locate(0,0);
20161773009 0:c443bef46896 40 lcd.printf("Motor Detenido");
20161773009 0:c443bef46896 41 Md=0;
20161773009 0:c443bef46896 42 Mi=0;
20161773009 0:c443bef46896 43 i=0;
20161773009 0:c443bef46896 44 }
20161773009 0:c443bef46896 45
20161773009 0:c443bef46896 46 else if(d==1 and key=='1'){
20161773009 0:c443bef46896 47 lcd.cls();
20161773009 0:c443bef46896 48 lcd.locate(0,0);
20161773009 0:c443bef46896 49 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 50 lcd.locate(0,1);
20161773009 0:c443bef46896 51 lcd.printf("Velocidad 1");
20161773009 0:c443bef46896 52 Md=0.2;
20161773009 0:c443bef46896 53 Mi=0;
20161773009 0:c443bef46896 54 i=0;
20161773009 0:c443bef46896 55 }
20161773009 0:c443bef46896 56
20161773009 0:c443bef46896 57 else if(d==1 and key=='2'){
20161773009 0:c443bef46896 58 lcd.cls();
20161773009 0:c443bef46896 59 lcd.locate(0,0);
20161773009 0:c443bef46896 60 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 61 lcd.locate(0,1);
20161773009 0:c443bef46896 62 lcd.printf("Velocidad 2");
20161773009 0:c443bef46896 63 Md=0.4;
20161773009 0:c443bef46896 64 Mi=0;
20161773009 0:c443bef46896 65 i=0;
20161773009 0:c443bef46896 66 }
20161773009 0:c443bef46896 67
20161773009 0:c443bef46896 68 else if(d==1 and key=='3'){
20161773009 0:c443bef46896 69 lcd.cls();
20161773009 0:c443bef46896 70 lcd.locate(0,0);
20161773009 0:c443bef46896 71 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 72 lcd.locate(0,1);
20161773009 0:c443bef46896 73 lcd.printf("Velocidad 3");
20161773009 0:c443bef46896 74 Md=0.6;
20161773009 0:c443bef46896 75 Mi=0;
20161773009 0:c443bef46896 76 i=0;
20161773009 0:c443bef46896 77 }
20161773009 0:c443bef46896 78 else if(d==1 and key=='4'){
20161773009 0:c443bef46896 79 lcd.cls();
20161773009 0:c443bef46896 80 lcd.locate(0,0);
20161773009 0:c443bef46896 81 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 82 lcd.locate(0,1);
20161773009 0:c443bef46896 83 lcd.printf("Velocidad 4");
20161773009 0:c443bef46896 84 Md=0.6;
20161773009 0:c443bef46896 85 Mi=0;
20161773009 0:c443bef46896 86 i=0;
20161773009 0:c443bef46896 87 }
20161773009 0:c443bef46896 88
20161773009 0:c443bef46896 89 else if(d==1 and key=='5'){
20161773009 0:c443bef46896 90 lcd.cls();
20161773009 0:c443bef46896 91 lcd.locate(0,0);
20161773009 0:c443bef46896 92 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 93 lcd.locate(0,1);
20161773009 0:c443bef46896 94 lcd.printf("Velocidad 5");
20161773009 0:c443bef46896 95 Md=0.8;
20161773009 0:c443bef46896 96 Mi=0;
20161773009 0:c443bef46896 97 i=0;
20161773009 0:c443bef46896 98 }
20161773009 0:c443bef46896 99
20161773009 0:c443bef46896 100 else if(d==1 and key=='6'){
20161773009 0:c443bef46896 101 lcd.cls();
20161773009 0:c443bef46896 102 lcd.locate(0,0);
20161773009 0:c443bef46896 103 lcd.printf("Motor Derecha");
20161773009 0:c443bef46896 104 lcd.locate(0,1);
20161773009 0:c443bef46896 105 lcd.printf("Velocidad 6");
20161773009 0:c443bef46896 106 Md=1;
20161773009 0:c443bef46896 107 Mi=0;
20161773009 0:c443bef46896 108 i=0;
20161773009 0:c443bef46896 109 }
20161773009 0:c443bef46896 110
20161773009 0:c443bef46896 111 else if(d==1 and key=='D'){
20161773009 0:c443bef46896 112 lcd.cls();
20161773009 0:c443bef46896 113 lcd.locate(0,0);
20161773009 0:c443bef46896 114 lcd.printf("Cambio de");
20161773009 0:c443bef46896 115 lcd.locate(0,1);
20161773009 0:c443bef46896 116 lcd.printf("Direccion");
20161773009 0:c443bef46896 117 Md=0;
20161773009 0:c443bef46896 118 Mi=0;
20161773009 0:c443bef46896 119 d=0;
20161773009 0:c443bef46896 120 i=0;
20161773009 0:c443bef46896 121
20161773009 0:c443bef46896 122 }
20161773009 0:c443bef46896 123
20161773009 0:c443bef46896 124 //released=0;
20161773009 0:c443bef46896 125
20161773009 0:c443bef46896 126
20161773009 0:c443bef46896 127
20161773009 0:c443bef46896 128 //}
20161773009 0:c443bef46896 129 }
20161773009 0:c443bef46896 130
20161773009 0:c443bef46896 131 void MotorIzquierda(){
20161773009 0:c443bef46896 132
20161773009 0:c443bef46896 133 key = teclado.ReadKey();
20161773009 0:c443bef46896 134
20161773009 0:c443bef46896 135 /*if(key == '\0')
20161773009 0:c443bef46896 136 released = 1;
20161773009 0:c443bef46896 137
20161773009 0:c443bef46896 138 if((key != '\0')&&(released == 1) ){*/
20161773009 0:c443bef46896 139 if(key=='B'){
20161773009 0:c443bef46896 140 lcd.cls();
20161773009 0:c443bef46896 141 lcd.locate(0,0);
20161773009 0:c443bef46896 142 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 143 i=1;
20161773009 0:c443bef46896 144 }
20161773009 0:c443bef46896 145 //while (d=1){
20161773009 0:c443bef46896 146 /*if(key==65){
20161773009 0:c443bef46896 147 lcd.cls();
20161773009 0:c443bef46896 148 lcd.locate(0,0);
20161773009 0:c443bef46896 149 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 150
20161773009 0:c443bef46896 151 }
20161773009 0:c443bef46896 152 */
20161773009 0:c443bef46896 153 if(i==1 and key==48){
20161773009 0:c443bef46896 154 lcd.cls();
20161773009 0:c443bef46896 155 lcd.locate(0,0);
20161773009 0:c443bef46896 156 lcd.printf("Motor Detenido");
20161773009 0:c443bef46896 157 Md=0;
20161773009 0:c443bef46896 158 Mi=0;
20161773009 0:c443bef46896 159 }
20161773009 0:c443bef46896 160
20161773009 0:c443bef46896 161 else if(i==1 and key==49){
20161773009 0:c443bef46896 162 lcd.cls();
20161773009 0:c443bef46896 163 lcd.locate(0,0);
20161773009 0:c443bef46896 164 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 165 lcd.locate(0,1);
20161773009 0:c443bef46896 166 lcd.printf("Velocidad 1");
20161773009 0:c443bef46896 167 Mi=0.2;
20161773009 0:c443bef46896 168 Md=0;
20161773009 0:c443bef46896 169 }
20161773009 0:c443bef46896 170
20161773009 0:c443bef46896 171 else if(i==1 and key==50){
20161773009 0:c443bef46896 172 lcd.cls();
20161773009 0:c443bef46896 173 lcd.locate(0,0);
20161773009 0:c443bef46896 174 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 175 lcd.locate(0,1);
20161773009 0:c443bef46896 176 lcd.printf("Velocidad 2");
20161773009 0:c443bef46896 177 Mi=0.4;
20161773009 0:c443bef46896 178 Md=0;
20161773009 0:c443bef46896 179 }
20161773009 0:c443bef46896 180
20161773009 0:c443bef46896 181 else if(i==1 and key==51){
20161773009 0:c443bef46896 182 lcd.cls();
20161773009 0:c443bef46896 183 lcd.locate(0,0);
20161773009 0:c443bef46896 184 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 185 lcd.locate(0,1);
20161773009 0:c443bef46896 186 lcd.printf("Velocidad 3");
20161773009 0:c443bef46896 187 Mi=0.6;
20161773009 0:c443bef46896 188 Md=0;
20161773009 0:c443bef46896 189 }
20161773009 0:c443bef46896 190 else if(i==1 and key==52){
20161773009 0:c443bef46896 191 lcd.cls();
20161773009 0:c443bef46896 192 lcd.locate(0,0);
20161773009 0:c443bef46896 193 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 194 lcd.locate(0,1);
20161773009 0:c443bef46896 195 lcd.printf("Velocidad 4");
20161773009 0:c443bef46896 196 Mi=0.6;
20161773009 0:c443bef46896 197 Md=0;
20161773009 0:c443bef46896 198 }
20161773009 0:c443bef46896 199
20161773009 0:c443bef46896 200 else if(i==1 and key==53){
20161773009 0:c443bef46896 201 lcd.cls();
20161773009 0:c443bef46896 202 lcd.locate(0,0);
20161773009 0:c443bef46896 203 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 204 lcd.locate(0,1);
20161773009 0:c443bef46896 205 lcd.printf("Velocidad 5");
20161773009 0:c443bef46896 206 Mi=0.8;
20161773009 0:c443bef46896 207 Md=0;
20161773009 0:c443bef46896 208 }
20161773009 0:c443bef46896 209
20161773009 0:c443bef46896 210 else if(i==1 and key==54){
20161773009 0:c443bef46896 211 lcd.cls();
20161773009 0:c443bef46896 212 lcd.locate(0,0);
20161773009 0:c443bef46896 213 lcd.printf("Motor Izquierda");
20161773009 0:c443bef46896 214 lcd.locate(0,1);
20161773009 0:c443bef46896 215 lcd.printf("Velocidad 6");
20161773009 0:c443bef46896 216 Mi=1;
20161773009 0:c443bef46896 217 Md=0;
20161773009 0:c443bef46896 218 }
20161773009 0:c443bef46896 219
20161773009 0:c443bef46896 220 else if(i==1 and key==68){
20161773009 0:c443bef46896 221 lcd.cls();
20161773009 0:c443bef46896 222 lcd.locate(0,0);
20161773009 0:c443bef46896 223 lcd.printf("Cambio de");
20161773009 0:c443bef46896 224 lcd.locate(0,1);
20161773009 0:c443bef46896 225 lcd.printf("Direccion");
20161773009 0:c443bef46896 226 Md=0;
20161773009 0:c443bef46896 227 Mi=0;
20161773009 0:c443bef46896 228 i=0;
20161773009 0:c443bef46896 229
20161773009 0:c443bef46896 230 }
20161773009 0:c443bef46896 231
20161773009 0:c443bef46896 232 //released=0;
20161773009 0:c443bef46896 233
20161773009 0:c443bef46896 234 // }
20161773009 0:c443bef46896 235
20161773009 0:c443bef46896 236 //}
20161773009 0:c443bef46896 237 }
20161773009 0:c443bef46896 238 int main() {
20161773009 0:c443bef46896 239 lcd.cls();
20161773009 0:c443bef46896 240 lcd.locate(0,0);
20161773009 0:c443bef46896 241 lcd.printf("Bienvenido");
20161773009 0:c443bef46896 242 lcd.locate(0,1);
20161773009 0:c443bef46896 243 lcd.printf("Grupo!");
20161773009 0:c443bef46896 244 wait(2);
20161773009 0:c443bef46896 245 lcd.cls();
20161773009 0:c443bef46896 246 lcd.locate(0,0);
20161773009 0:c443bef46896 247 lcd.printf("Integrantes:");
20161773009 0:c443bef46896 248 wait(2);
20161773009 0:c443bef46896 249 lcd.cls();
20161773009 0:c443bef46896 250 lcd.locate(0,0);
20161773009 0:c443bef46896 251 lcd.printf("Maikol Zarate");
20161773009 0:c443bef46896 252 lcd.locate(0,1);
20161773009 0:c443bef46896 253 lcd.printf("Brandon Bernal");
20161773009 0:c443bef46896 254 wait(2);
20161773009 0:c443bef46896 255 lcd.cls();
20161773009 0:c443bef46896 256
20161773009 0:c443bef46896 257
20161773009 0:c443bef46896 258 while(1){
20161773009 0:c443bef46896 259 MotorDerecha();
20161773009 0:c443bef46896 260 MotorIzquierda();
20161773009 0:c443bef46896 261 }
20161773009 0:c443bef46896 262 }
20161773009 0:c443bef46896 263
20161773009 0:c443bef46896 264
20161773009 0:c443bef46896 265