Code

Dependencies:   mbed QEI MPU6050 TextLCD

main.cpp

Committer:
belsarekaiwalya
Date:
2017-03-14
Revision:
1:59c416ccba42
Parent:
0:c9c8c027609e
Child:
2:156f4732fbf1

File content as of revision 1:59c416ccba42:

#include "mbed.h"
/*DigitalOut myled(LED1);
DigitalOut m2dir1(PB_4);
DigitalOut m2dir2(PB_10);
DigitalOut m1dir1(PB_3);
DigitalOut m1dir2(PB_5);
PwmOut pwm1(PA_8);
PwmOut pwm2(PA_9);

int main() {
    
        pwm1.period_ms(1);
        pwm1 = 1;
    
        pwm2.period_ms(1);
        pwm2 = 1;
    
    while(1) 
    {
        m2dir1 = 1;
        m2dir2 = 0;
        m1dir1 = 1;
        m1dir2 = 0;
  
  
        //lcd.locate(1,0);
        //lcd.printf("Hello\n");
        //myled = 1; // LED is ON
        //wait(0.2); // 200 ms
        //myled = 0; // LED is OFF
        //wait(1.0); // 1 sec
    
    }
}
*/
#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // rs, e, d4-d7
DigitalOut dirRa(PB_3);
DigitalOut dirRb(PB_5);
DigitalOut dirLa(PB_4);
DigitalOut dirLb(PB_10);
PwmOut pwmL(PA_8);//left
PwmOut pwmR(PA_9);//right 

Serial bt(PC_6,PC_7);//tx,rx
PwmOut mypwm(LED1);
DigitalOut myled(LED1);
Serial serial(USBTX, USBRX);

int ch ;
int main()
{
    bt.baud(9600);
    serial.baud(9600);
    void brake();
    while(1) 
    {
        if(bt.readable()) 
        {
         ch =  bt.getc();
         lcd.cls();  
         switch(ch)
            {
              case 'w'://Front
              void front();
              dirRa = 1;
              dirRb = 0;
              dirLa = 1;
              dirLb = 0;
              pwmL.period_ms(1); 
              pwmL=0.5;
              pwmR.period_ms(1); 
              pwmR=0.5; 
    
              lcd.cls();
              serial.printf("Forward\n");
              lcd.locate(1,0);
              lcd.printf("Forward\n");
              break;
              
              case 'a'://Left
               dirRa = 1;
               dirRb = 0;
               dirLa = 0;
               dirLb = 0;
               pwmL.period_ms(1); 
               pwmL=0;
               pwmR.period_ms(1); 
               pwmR=0.5; 
   
               lcd.cls();
               serial.printf("Left\n");
               lcd.locate(1,0);
               lcd.printf("Left\n");
               //void left();
              break; 
              
              case 's'://Back
              dirRa = 0;
              dirRb = 1;
              dirLa = 0;
              dirLb = 1;
              pwmL.period_ms(1); 
              pwmL=0.5;
              pwmR.period_ms(1); 
              pwmR=0.5;
    
              lcd.cls();
              serial.printf("Back\n");
              lcd.locate(1,0);
              lcd.printf("Back\n");
              void back();
              break; 
              
              case 'd'://Right
               dirRa = 0;
               dirRb = 0;
               dirLa = 1;
               dirLb = 0;
               pwmL.period_ms(1); 
               pwmL=0.5f;
               pwmR.period_ms(1); 
               pwmR=0; 
   
              lcd.cls();
              serial.printf("Right\n");
              lcd.locate(1,0);
              lcd.printf("Right\n");
              void right();
              break;
              
              case 'O'://Stop
              dirRa = 1;
              dirRb = 0;
              dirLa = 1;
              dirLb = 0;
              pwmL.period_ms(1); 
              pwmL=0;
              pwmR.period_ms(1); 
              pwmR=0; 
    
              lcd.cls();
              serial.printf("STOP\n");
              lcd.locate(1,0);
              lcd.printf("STOP\n");
              void Brake();
              break;
              
              case 'A'://Anticlock
               dirRa = 1;
               dirRb = 0;
               dirLa = 0;
               dirLb = 1;
               pwmL.period_ms(1); 
               pwmL=0.5;
               pwmR.period_ms(1); 
               pwmR=0.5; 
   
               lcd.cls();
               serial.printf("AntiClock\n");
               lcd.locate(1,0);
               lcd.printf("AntiClock\n");
               break; 
              
              case 'C'://Clock
               dirRa = 0;
               dirRb = 1;
               dirLa = 1;
               dirLb = 0;
               pwmL.period_ms(1); 
               pwmL=0.5f;
               pwmR.period_ms(1); 
               pwmR=0.5f;
   
              lcd.cls();
              serial.printf("Clock\n");
              lcd.locate(1,0);
              lcd.printf("Clock\n");
              break;
              
              
              
              
              
              default:
              serial.printf("Brake");
              lcd.cls();
              lcd.locate(1,0);
              lcd.printf("Brake");
              void brake();
                
                }
        
        }
        
        //serial.printf("%c\n",ch);
    }
}
void front()
{
    
    dirRa = 1;
    dirRb = 0;
    dirLa = 1;
    dirLb = 0;
    pwmL.period_ms(1); 
    pwmL=0.5;
    pwmR.period_ms(1); 
    pwmR=0.5; 
    
}
void brake()
{
    dirRa = 0;
    dirRb = 0;
    dirLa = 0;
    dirLb = 0;
    pwmL.period_ms(1); 
    pwmL=0.0;
    pwmR.period_ms(1); 
    pwmR=0.0; 
    
}
void back()
{
    dirRa = 0;
    dirRb = 1;
    dirLa = 0;
    dirLb = 1;
    pwmL.period_ms(1); 
    pwmL=0.5;
    pwmR.period_ms(1); 
    pwmR=0.5;
    
}
void left()
{
    dirRa = 0;
    dirRb = 1;
    dirLa = 0;
    dirLb = 0;
    pwmL.period_ms(1); 
    pwmL=0.5;
    pwmR.period_ms(1); 
    pwmR=0.0; 
    
}
void right()
{
    dirRa = 0;
    dirRb = 0;
    dirLa = 0;
    dirLb = 1;
    pwmL.period_ms(1); 
    pwmL=0.0f;
    pwmR.period_ms(1); 
    pwmR=0.5f; 
    
}