Make my motor go back

Hi everyone

I'm a newbie in Arduino and I must make a Line follower robot for a school project.

I managed to move the robot around thanks to the two motors by making one of them go slower or faster, but I would like to make them go backwards in case it goes out of track.

The problem is I don't find the code for that :slightly_frowning_face:

I'm working with an Makeblock Me Orion, here is what I've already done

include "MeOrion.h"

MeDCMotor moteurg(M1);

MeDCMotor moteurd(M2);

int slow = 30; int fast = 60; int rev = 0;

MeLineFollower lineFinder(PORT_3);

void setup() { Serial.begin(9600); }

void loop() { int sensorState = lineFinder.readSensors(); switch(sensorState) { case S1_IN_S2_IN: moteurg.run(fast); moteurd.run(fast); //go ahead break;

case S1_IN_S2_OUT: moteurg.run(fast); moteurd.run(slow); //go left break;

case S1_OUT_S2_IN: moteurg.run(slow); moteurd.run(fast); //go right break;

case S1_OUT_S2_OUT: moteurg.run(rev); moteurd.run(rev); break; default: break; } }

Check the documentation for MeOrion.