Created
March 15, 2019 09:23
-
-
Save timlambrecht/fdcd40036222903ae371b272dabf7d08 to your computer and use it in GitHub Desktop.
Code for Me Sensor and DCMotor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MeOrion.h" | |
MeDCMotor motor1(PORT_1); | |
MeDCMotor motor2(PORT_2); | |
MeDCMotor motor3(M1); | |
MeDCMotor motor4(M2); | |
MeUltrasonicSensor SensorL(PORT_6); | |
MeUltrasonicSensor SensorM(PORT_7); /* Ultrasonic module can ONLY be connected to port 3, 4, 6, 7, 8 of base shield. */ | |
MeUltrasonicSensor SensorR(PORT_8); | |
void setup() | |
{ | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
Serial.print("SensorL : "); | |
Serial.print(SensorL.distanceCm() ); | |
Serial.println(" cm"); | |
Serial.print("SensorM : "); | |
Serial.print(SensorM.distanceCm() ); | |
Serial.println(" cm"); | |
Serial.print("SensorR : "); | |
Serial.print(SensorR.distanceCm() ); | |
Serial.println(" cm"); | |
delay(100); /* the minimal measure interval is 100 milliseconds */ | |
if (SensorL.distanceCm() > 15 and SensorM.distanceCm() > 15 and SensorR.distanceCm() > 15){ | |
vooruit(); | |
} | |
if (SensorL.distanceCm() < 15 || SensorM.distanceCm() < 15 || SensorR.distanceCm() < 15){ | |
wacht(); | |
delay(1000); | |
draai_links(); | |
delay(650); | |
} | |
} | |
void vooruit(){ | |
motor1.run(100); /* achterwiel links: between 0 and -255 */ | |
motor2.run(100); /* achterwiel rechts: between 0 and -255 */ | |
motor3.run(100); /* voorwiel links: between 0 and 255. */ | |
motor4.run(100); /* voorwiel rechts: between 0 and 255. */ | |
} | |
void achteruit(){ | |
motor1.run(-100); /* achterwiel links: between 0 and -255 */ | |
motor2.run(-100); /* achterwiel rechts: between 0 and -255 */ | |
motor3.run(-100); /* voorwiel links: between 0 and 255. */ | |
motor4.run(-100); /* voorwiel rechts: between 0 and 255. */ | |
} | |
void draai_links(){ | |
motor1.run(-100); /* achterwiel links: between 0 and -255 */ | |
motor2.run(100); /* achterwiel rechts: between 0 and -255 */ | |
motor3.run(-100); /* voorwiel links: between 0 and 255. */ | |
motor4.run(100); /* voorwiel rechts: between 0 and 255. */ | |
} | |
void draai_rechts(){ | |
motor1.run(100); /* achterwiel links: between 0 and -255 */ | |
motor2.run(-100); /* achterwiel rechts: between 0 and -255 */ | |
motor3.run(100); /* voorwiel links: between 0 and 255. */ | |
motor4.run(-100); /* voorwiel rechts: between 0 and 255. */ | |
} | |
void wacht(){ | |
motor1.run(0); /* achterwiel links: between 0 and -255 */ | |
motor2.run(0); /* achterwiel rechts: between 0 and -255 */ | |
motor3.run(0); /* voorwiel links: between 0 and 255. */ | |
motor4.run(0); /* voorwiel rechts: between 0 and 255. */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment