#include "MeOrion.h"
MeDCMotor motor(M1);
MeUltrasonicSensor ultraSensor(PORT_7);
void setup() {
Serial.begin(9600);
}
void loop() {
float distance = ultraSensor.distanceCm();
Serial.print("Distance : ");
Serial.print(distance);
Serial.print(" cm");
delay(100);
int motorSpeed = 255;
if(distance > 100){
motor.run(motorSpeed);}
if(distance > 80 && distance <=100) {
motor.run(motorSpeed-40);}
else if(distance > 60 && distance <=80){
motor.run(motorSpeed-80);}
else if(distance > 30 && distance <=60){
motor.run(motorSpeed-120);}
else if(distance > 10 && distance <=30){
motor.run(motorSpeed-160) ;}
else{
motor.run(-motorSpeed);}
}