#include #include /* * les fins de courses semblent etre sur A3 et A4 reliant le GND a ces pins. * moteur1: arecabler i1=P8, i2=P10, i3=P11, i14=p12 moteur2: i1=P4, i2=P5, i3=P6, i4=P7 speaker: pin9 This sketch demonstrates simple collision detection without using the built in library code from https://github.com/mirobot/mirobot-arduino by http://www.Mirobot.io */ Mirobot mirobot; typedef enum {M_NORMAL, M_RIGHT_REVERSE, M_RIGHT_TURN, M_LEFT_REVERSE, M_LEFT_TURN} collideState_ty; collideState_ty collideState; void setup(){ mirobot.setup(); } void loop(){ boolean collideLeft = !digitalRead(LEFT_COLLIDE_SENSOR); boolean collideRight = !digitalRead(RIGHT_COLLIDE_SENSOR); if(collideState == M_NORMAL){ if(collideLeft){ collideState = M_LEFT_REVERSE; mirobot.back(50); }else if(collideRight){ collideState = M_RIGHT_REVERSE; //recule de 50 mirobot.back(50); }else{ //avance de 10 mirobot.forward(10); } }else if(mirobot.ready()){ switch(collideState){ case M_LEFT_REVERSE : collideState = M_LEFT_TURN; mirobot.right(90); break; case M_RIGHT_REVERSE : collideState = M_RIGHT_TURN; mirobot.left(90); break; case M_LEFT_TURN : case M_RIGHT_TURN : collideState = M_NORMAL; } } }