Version 1

Dependencies:   mbed m3pi_pops

main.cpp

Committer:
emilienb
Date:
2019-10-25
Revision:
0:286c78fcd9dd
Child:
1:ef658023014b

File content as of revision 0:286c78fcd9dd:

#include "mbed.h"
#include "m3pi.h"
//#include "MSCFileSystem.h"

m3pi pololu;

Serial usb(USBTX,USBRX);

DigitalOut l1(LED1);
DigitalOut l2(LED2);
DigitalOut l3(LED3);
DigitalOut l4(LED4);

float speed = 0.5;

int main() {    

int capteurs[5]={1,1,1,1,1};
char buff[8];
char c,cprev;
    while(1) {
        //affichage valeur capteur 
        //Boucle switch de reception de données via serial
        if(usb.readable()){
            cprev=c;
            c = usb.getc();
            switch(c){ 
            case 'z':
                pololu.forward(speed);
                l1 = 1;
                l2 = 0;
                l3 = 0;
                l4 = 0;
                break;
            case 's':    
                pololu.backward(speed);
                l1 = 0;
                l2 = 1;
                l3 = 0;
                l4 = 0;
                break;
            case 'q':    
                pololu.left(0.3);
                l1 = 1;
                l2 = 0;
                l3 = 0;
                l4 = 0;
                break;
            case 'd':    
                pololu.right(0.3);
                l1 = 1;
                l2 = 0;
                l3 = 0;
                l4 = 0;
                break;
            case 'a': 
                speed += 0.1;       
                if(speed > 1) speed = 1;
                pololu.cls();
                pololu.locate(0,0);
                sprintf(buff, "Spd:%3.f",speed );
                pololu.print(buff,8);
                
                break;
            case 'e': 
                speed -= 0.1;   
                if(speed < 0) speed = 0;
                pololu.cls();
                pololu.locate(0,0);
                sprintf(buff, "Spd:%3.f",speed );
                pololu.print(buff,8);
                break;
            case ' ':    
                pololu.stop();
                l1 = 1;
                l2 = 1;
                l3 = 1;
                l4 = 1;
                break;
            case 'c':
                pololu.calibrate();
                pololu.readsensor(capteurs);
                 if(usb.writable()) {
                        usb.printf("%d, %d, %d, %d, %d | \0",capteurs[0],capteurs[1],capteurs[2],capteurs[3],capteurs[4]);}
            case 'b':
                sprintf(buff, "Bat:%3.f",pololu.battery());
                pololu.cls();
                pololu.locate(0,0);
                pololu.print(buff,8);
            case 'y' : 
                speed = 0.3;
                pololu.forward(speed);
                wait(3);
                pololu.stop();
                wait(1);
                pololu.left(speed);
                wait(2);
                pololu.right(speed);
                wait(1);            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
            default : break; 
            }
        }
    }
}