Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- burgerking
- Date:
- 2020-05-03
- Revision:
- 21:39815fb7e4f5
- Parent:
- 20:fa411d58e3ee
- Child:
- 22:64fa6f501426
File content as of revision 21:39815fb7e4f5:
#include "mbed.h"
#include "C12832.h"
#include "moteur.h"
#include "emissionIR.h"
/* Déclaration des objets glogaux ***************************/
C12832 lcd(D11, D13, D12, D7, D10);
AnalogIn pot1(A0);
AnalogIn pot2(A1);
DigitalOut LED_rouge(D5,1);
DigitalOut LED_verte(D9,1);
//DigitalOut LED_bleue(D8,1); // NE PAS UTILISER LA LED BLEUE
DigitalIn up(A2);
DigitalIn down(A3);
DigitalIn left(A4);
DigitalIn right(A5);
DigitalIn fire(D4);
// Détecteurs d'obstacles
AnalogIn IR_G(PB_1);AnalogIn IR_D(PC_2);
DigitalIn jack(PD_2);
DigitalIn bumpers(PB_7);
DigitalOut LED(PA_13);
// Détecteur de zone blanche
BusIn Arrivee(PC_9,PC_10,PC_11,PC_12,PA_12,PA_14);
Serial uartWifi(SERIAL_TX, SERIAL_RX);
//Serial uartWifi(PA_9, PA_10);
/* Déclaration des variables globales ****************************************/
/* Définition des fonctions gérant la machine à états ************************/
// définition des fonctions
void gestionEtat(){
}
void gestionAction(){
}
/******************************************************************************/
enum Machine_A_Etat
{
Depart,Navigation,Arrive,Evitement,Rotation
};
int main() {
int iState=Depart;
int distObsGauche=pot1.read();
int distObsDroite=pot2.read();
int bumpers=bumpers.read();
int up=up.read();
int jack=jack.read();
int fire=fire.read();
lcd.cls();
lcd.locate(32,16);
lcd.printf("Module ER2 : template");
while(true){
wait(.5);
switch(iState){
case Depart :
LED_verte.write(1);
//printf.lcd("Depart");
break;
case Navigation :
//No Yellow LED
commandeMoteurs(50,50);
//printf.lcd("Navigation");
break;
case Arrive :
LED_verte.write(!LED_verte.read());
commandeMoteurs(0,0);
//printf.lcd("Arrive");
break;
case Evitement :
LED_rouge.write(1);
if(distObsDroite>distObsGsuche)
comandeMoteur(100,0);
//printf.lcd("Evitement1");
else
commandeMoteur(0,100);
//printf.lcd("Evitement2");
break;
case Rotation :
LED_rouge.write(!LED_rouge.read());
if(distObsDroite>distObsGsuche)
comandeMoteur(100,0);
//printf.lcd("Rotation1");
else
commandeMoteur(0,100);
//printf.lcd("Rotation2");
break;
}//switch
while(iState=Depart)
{
if(jack==0||fire==1)
iState=Navigation;
if(up==1)
iState=Arrive;
}
while(iState=Navigation)
{
if(//distObsGauche>20cm||distObsDroite>20cm)
iState=Rotation;
if(//20cm<distObsGauche<40cm&&20cm<distObsDroite<0cm)
iState=Evitation;
if(/*white tested*/||bumpers==1)
iState=Arrive;
}
while(iState=Arrivee)
{
if(up==1)
iState=Depart;
}
while(iState=Evitement)
{
if(//distObsGauche<20cm||distObsDroite<20cm)
iState=Rotation;
if(//distObsGauche>40cm&&distObsDroite>40cm)
iState=Navigation;
if(/*white tested*/||bumpers==1)
iState=Arrive;
}
while(iState=Rotation)
{
if(//distObsGauche>40cm&&distObsDroite>40cm)
iState=Navigation;
if(/*white tested*/||bumpers==1)
iState=Evitement;
}
}//while
}