41 lines
849 B
C++
41 lines
849 B
C++
#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);
|
|
}
|