.

Dependencies:   mbed TextLCD Keypad

main.cpp

Committer:
20161773009
Date:
2020-03-09
Revision:
0:c443bef46896

File content as of revision 0:c443bef46896:

#include "mbed.h"
#include "TextLCD.h"
#include "Keypad.h"

PwmOut  Md(PTA2)PwmOut  Md(PTD4);
PwmOut  Mi(PTA1);
PwmOut  Md(PTD4);
PwmOut  Mi(PTA12);
TextLCD lcd(PTB8,PTB9,PTB10,PTB11,PTE2,PTE3,TextLCD::LCD16x2);
Keypad teclado(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5);
int d=0, i=0;
char key;                  //char porque se recibe de teclado caracteres
int released=1;            //entero que nos dice cuando hay pulso en el teclado
    
void MotorDerecha(){
        
    key = teclado.ReadKey();

    /*   if(key == '\0')
          released = 1;
          
       if((key != '\0')&&(released == 1) ){*/
          if(key=='A'){
            lcd.cls(); 
            lcd.locate(0,0); 
            lcd.printf("Motor Derecha");
            d=1;
            }
            //while (d=1){
            /*if(key==65){
            lcd.cls(); 
            lcd.locate(0,0); 
            lcd.printf("Motor Derecha");
            
            }
            */
            if(d==1 and key=='0'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Detenido");
                Md=0;
                Mi=0;
                i=0;
              }
              
            else if(d==1 and key=='1'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 1");
                Md=0.2;
                Mi=0;
                i=0;
              }
              
            else if(d==1 and key=='2'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 2");
                Md=0.4;
                Mi=0;
                i=0;
              }
              
            else if(d==1 and key=='3'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 3");
                Md=0.6;
                Mi=0;
                i=0;
              }
            else if(d==1 and key=='4'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 4");
                Md=0.6;
                Mi=0;
                i=0;
              }
            
            else if(d==1 and key=='5'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 5");
                Md=0.8;
                Mi=0;
                i=0;
              }
            
            else if(d==1 and key=='6'){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Derecha");
                lcd.locate(0,1);
                lcd.printf("Velocidad 6");
                Md=1;
                Mi=0;
                i=0;
              }
              
            else if(d==1 and key=='D'){
                lcd.cls();
                lcd.locate(0,0);
                lcd.printf("Cambio de");
                lcd.locate(0,1);
                lcd.printf("Direccion");
                Md=0;
                Mi=0;
                d=0;
                i=0;
                
              }  
          
          //released=0; 
                  
    

    //}
}

void MotorIzquierda(){
        
    key = teclado.ReadKey();

       /*if(key == '\0')
          released = 1;
          
       if((key != '\0')&&(released == 1) ){*/
          if(key=='B'){
            lcd.cls(); 
            lcd.locate(0,0); 
            lcd.printf("Motor Izquierda");
            i=1;
            }
            //while (d=1){
            /*if(key==65){
            lcd.cls(); 
            lcd.locate(0,0); 
            lcd.printf("Motor Izquierda");
            
            }
            */
            if(i==1 and key==48){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Detenido");
                Md=0;
                Mi=0;
              }
              
            else if(i==1 and key==49){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 1");
                Mi=0.2;
                Md=0;
              }
              
            else if(i==1 and key==50){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 2");
                Mi=0.4;
                Md=0;
              }
              
            else if(i==1 and key==51){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 3");
                Mi=0.6;
                Md=0;
              }
            else if(i==1 and key==52){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 4");
                Mi=0.6;
                Md=0;
              }
            
            else if(i==1 and key==53){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 5");
                Mi=0.8;
                Md=0;
              }
            
            else if(i==1 and key==54){
                lcd.cls();
                lcd.locate(0,0); 
                lcd.printf("Motor Izquierda");
                lcd.locate(0,1);
                lcd.printf("Velocidad 6");
                Mi=1;
                Md=0;
              }
              
            else if(i==1 and key==68){
                lcd.cls();
                lcd.locate(0,0);
                lcd.printf("Cambio de");
                lcd.locate(0,1);
                lcd.printf("Direccion");
                Md=0;
                Mi=0;
                i=0;
                
              }  
          
          //released=0; 
                  
//    }

    //}
}
int main() {
    lcd.cls();
    lcd.locate(0,0); 
    lcd.printf("Bienvenido");
    lcd.locate(0,1); 
    lcd.printf("Grupo!");
    wait(2);
    lcd.cls();
    lcd.locate(0,0);
    lcd.printf("Integrantes:");
    wait(2);
    lcd.cls();
    lcd.locate(0,0); 
    lcd.printf("Maikol Zarate");
    lcd.locate(0,1); 
    lcd.printf("Brandon Bernal");
    wait(2);
    lcd.cls();
    
    
  while(1){
      MotorDerecha();
      MotorIzquierda();
}
}