![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code
Dependencies: mbed QEI MPU6050 TextLCD
main.cpp
- Committer:
- belsarekaiwalya
- Date:
- 2017-03-11
- Revision:
- 0:c9c8c027609e
- Child:
- 1:59c416ccba42
File content as of revision 0:c9c8c027609e:
/*#include "mbed.h" DigitalOut myled(LED1); int main() { while(1) { 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 m1dir1(PB_3); DigitalOut m1dir2(PB_5); DigitalOut m2dir1(PB_4); DigitalOut m2dir2(PB_10); PwmOut pwm1(PA_8); PwmOut pwm2(PA_9); 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); while(1) { if(bt.readable()) { ch = bt.getc(); lcd.cls(); switch(ch) { case 'w': lcd.cls(); serial.printf("Forward\n"); lcd.locate(1,0); lcd.printf("Forward\n"); void front(); break; case 'a': lcd.cls(); serial.printf("Left\n"); lcd.locate(1,0); lcd.printf("Left\n"); void left(); break; case 's': lcd.cls(); serial.printf("Back\n"); lcd.locate(1,0); lcd.printf("Back\n"); void back(); break; case 'd': lcd.cls(); serial.printf("Right\n"); lcd.locate(1,0); lcd.printf("Right\n"); void right(); break; default: serial.printf("Brake"); lcd.cls(); lcd.locate(1,0); lcd.printf("Brake"); void brake(); } } //serial.printf("%c\n",ch); } } void front() { m1dir1 = 1; m1dir2 = 0; m2dir1 = 1; m2dir2 = 0; pwm1.period(0.001f); pwm1=0.5; pwm2.period(0.001f); pwm2=0.5; } void brake() { m1dir1 = 1; m1dir2 = 0; m2dir1 = 1; m2dir2 = 0; pwm1.period(0.001f); pwm1=0.0f; pwm2.period(0.001f); pwm2=0.0f; } void back() { m1dir1 = 0; m1dir2 = 1; m2dir1 = 0; m2dir2 = 1; pwm1.period(0.001f); pwm1=0.5; pwm2.period(0.001f); pwm2=0.5; } void left() { m1dir1 = 0; m1dir2 = 1; m2dir1 = 0; m2dir2 = 0; pwm1.period(0.001f); pwm1=0.5f; pwm2.period(0.001f); pwm2=0.0f; } void right() { m1dir1 = 0; m1dir2 = 0; m2dir1 = 0; m2dir2 = 1; pwm1.period(0.001f); pwm1=0.0f; pwm2.period(0.001f); pwm2=0.5; }