28 lines
352 B
C++
28 lines
352 B
C++
#include "MeMCore.h"
|
|
|
|
MeDCMotor motor1(9);
|
|
|
|
MeDCMotor motor2(10);
|
|
|
|
MeUltrasonicSensor ultraSensor(PORT_3);
|
|
|
|
int minDistance = 15;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void loop() {
|
|
|
|
if (ultraSensor.distanceCm()<minDistance){
|
|
motor1.run(100);
|
|
motor2.run(100);
|
|
delay(800);
|
|
}
|
|
else {
|
|
motor1.run(-155);
|
|
motor2.run(155);
|
|
}
|
|
|
|
}
|