Code
Dependencies: mbed QEI MPU6050 TextLCD
Revision 3:86145fd89b45, committed 2017-03-22
- Comitter:
- belsarekaiwalya
- Date:
- Wed Mar 22 06:42:53 2017 +0000
- Parent:
- 2:156f4732fbf1
- Child:
- 4:b084af72f9a6
- Commit message:
- Checked and tested with the corresponding pwm pins for left and right.; Includes front,back,left,right,clock and anticlock motion.Includes LCD, Bluetooth HC-05.;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 14 15:34:06 2017 +0000 +++ b/main.cpp Wed Mar 22 06:42:53 2017 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "TextLCD.h" TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); // rs, e, d4-d7 +Serial serial(USBTX, USBRX); +Serial bt(PC_6,PC_7);//tx,rx DigitalOut dirRa(PB_3); DigitalOut dirRb(PB_5); DigitalOut dirLa(PB_4); @@ -8,17 +10,34 @@ 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); +void InitSerial(); +void front(float xpwmL,float xpwmR); +void back(float xpwm,float xpwmR); +void left(float xpwm, float xpwmR); +void right(float xpwm,float xpwmR); +void clockWise(float xpwm,float xpwmR); +void antiClock(float xpwm,float xpwmR); +void Brake(); -int ch ; -int main() +int ch; + +void InitSerial() { bt.baud(9600); serial.baud(9600); - void brake(); +} +void SetPwmf_kHz(float freq) +{ + + pwmL.period_ms(freq); + pwmR.period_ms(freq); + +} +int main() +{ + InitSerial(); + SetPwmf_kHz(1); + Brake(); while(1) { if(bt.readable()) @@ -28,198 +47,135 @@ 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; - + front(0.5,0.5); + serial.printf("Forward\n"); + lcd.cls(); + 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; - + left(0,0.5); + serial.printf("Left\n"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("Left\n"); + 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; - + back(0.5,0.5); + serial.printf("Back\n"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("Back\n"); + 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; - + right(0.5,0); + serial.printf("Right\n"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("Right\n"); + 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; - + Brake(); + serial.printf("STOP\n"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("STOP\n"); + 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; - + antiClock(0.5,0.5); + serial.printf("AntiClock\n"); + lcd.cls(); + 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; - - - - + clockWise(0.5,0.5); + serial.printf("Clock\n"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("Clock\n"); + break; default: - serial.printf("Brake"); - lcd.cls(); - lcd.locate(1,0); - lcd.printf("Brake"); - void brake(); - - } - + Brake(); + serial.printf("Brake"); + lcd.cls(); + lcd.locate(1,0); + lcd.printf("Brake"); + } } - - //serial.printf("%c\n",ch); } } -void front() -{ +void front(float xpwmL,float xpwmR) +{ + dirLa = 1; + dirLb = 0; + pwmL= xpwmL; dirRa = 1; dirRb = 0; + pwmR= xpwmR; +} +void back(float xpwmL,float xpwmR) +{ + dirLa = 0; + dirLb = 1; + pwmL= xpwmL; + + dirRa = 0; + dirRb = 1; + pwmR= xpwmR; +} +void left(float xpwmL,float xpwmR) +{ + dirLa = 0; + dirLb = 0; + pwmL= xpwmL; + + dirRa = 1; + dirRb = 0; + pwmR= xpwmR; +} +void right(float xpwmL,float xpwmR) +{ dirLa = 1; dirLb = 0; - pwmL.period_ms(1); - pwmL=0.5; - pwmR.period_ms(1); - pwmR=0.5; + pwmL = xpwmL; + dirRa = 0; + dirRb = 0; + pwmR = xpwmR; } -void brake() +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() +void antiClock(float xpwmL,float xpwmR) +{ + dirRa = 1; + dirRb = 0; + dirLa = 0; + dirLb = 1; + pwmL = xpwmL; + pwmR = xpwmR; +} +void clockWise(float xpwmL,float xpwmR) { 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; + dirLa = 1; 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; - -} + pwmL = xpwmL; + pwmR = xpwmR; +} \ No newline at end of file