![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
remoteContolledRobot via Bluetooth HC06
Dependencies: PWMOut Servo mbed
main.cpp
- Committer:
- 9acem
- Date:
- 2017-04-12
- Revision:
- 0:216ced19d510
File content as of revision 0:216ced19d510:
#include "mbed.h" #include "Servo.h" Serial bt(D10,D2); // rx BT,tx BT Servo outil(D3); Servo porte(D13); //D4 twali D13 Servo pivot(D5); PwmOut avd(D7); //in 1 PwmOut ard(D6); //in 2 PwmOut avg(D8); //in 3 PwmOut arg(D9); //in 4 void avancer() { avd=1.0; ard=0; avg=1.0; arg=0; } void avancerL() { avd=0.5; ard=0; avg=0.5; arg=0; } void reculer() { avd=0; ard=1.0; avg=0; arg=1.0; } void reculerL() { avd=0; ard=0.5; avg=0; arg=0.5; } void droite() { avd=0; ard=0; avg=1.0; arg=0; } void droitesp() { avd=0; ard=1.0; avg=1.0; arg=0; } void gauche() { avd=1.0; ard=0; avg=0; arg=0; } void gauchesp() { avd=1.0; ard=0; avg=0; arg=1.0; } void stoop() { avd=0; ard=0; avg=0; arg=0; } int main() { bt.baud(9600); porte.calibrate(0.00095, 90.0); // Calibrate the servo outil.calibrate(0.00095, 90.0); // Calibrate the servo pivot.calibrate(0.00095, 90.0); // Calibrate the servo /*initialisation des servos*/ porte.write(0.15);//porte en haut pivot.write(0.8); //outil avant rotation position initial wait(1); outil.write(0.92); //outil en bas D11 while(1) { //For reading and writing data from/to bluetooth HC-06 //check if bluetooth is readable and execute commands to toggle LED if (bt.readable()) { char input_key= bt.putc(bt.getc()); switch (input_key) { case 'A' : pivot.write(0.8); //outil avant rotation position initial pivot.write(0.8) wait(1); outil.write(0.92); //outil en bas D11 break; case 'B' : outil.write(0.35);// outil en: haut outil.write(0.54); wait(1); pivot.write(0.38);// outil pivoté 90°: pivot.write(0.38) break; case '6' : porte.write(0.15); //porte en haut break; case '5' : porte.write(0.83);// porte en bas break; case 'U': avancer();break; case '1': avancerL (); break; case 'D': reculer ();break; case '3': reculerL(); break; case '8': droitesp ();break; case '7': gauchesp ();break; case 'R': droite();break; case 'L': gauche() ;break; case 'S': stoop(); break; default : stoop();break; } } } }