Line follower
This commit is contained in:
parent
3c0b12d1c4
commit
3b80a73784
|
|
@ -0,0 +1,40 @@
|
|||
#include "MeMCore.h"
|
||||
|
||||
MeLineFollower lineFinder(PORT_2);
|
||||
MeDCMotor motor1(9);
|
||||
|
||||
MeDCMotor motor2(10);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int sensorState = lineFinder.readSensors();
|
||||
switch(sensorState)
|
||||
{
|
||||
case S1_IN_S2_IN:
|
||||
Serial.println("Sensor 1 and 2 are inside of black line");
|
||||
motor1.run(-100);
|
||||
motor2.run(100);
|
||||
break;
|
||||
case S1_IN_S2_OUT:
|
||||
Serial.println("Sensor 2 is outside of black line");
|
||||
motor1.run(100);
|
||||
motor2.run(100);
|
||||
break;
|
||||
case S1_OUT_S2_IN:
|
||||
Serial.println("Sensor 1 is outside of black line");
|
||||
motor1.run(-100);
|
||||
motor2.run(-100);
|
||||
break;
|
||||
case S1_OUT_S2_OUT:
|
||||
Serial.println("Sensor 1 and 2 are outside of black line");
|
||||
motor1.run(100);
|
||||
motor2.run(100);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
delay(50);
|
||||
}
|
||||
Loading…
Reference in New Issue