merge develop 3
This commit is contained in:
commit
986093f958
|
|
@ -0,0 +1,47 @@
|
||||||
|
#include <MeMCore.h>
|
||||||
|
|
||||||
|
|
||||||
|
MeUltrasonicSensor sensor(3);
|
||||||
|
|
||||||
|
MeDCMotor leftRotor(9);
|
||||||
|
MeDCMotor rightRotor(10);
|
||||||
|
|
||||||
|
float distance;
|
||||||
|
|
||||||
|
float lSpeed;
|
||||||
|
float rSpeed;
|
||||||
|
float duration;
|
||||||
|
int Side;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
Serial.begin(9600);
|
||||||
|
leftRotor.run(0);
|
||||||
|
rightRotor.run(0);
|
||||||
|
lSpeed = -200.0;
|
||||||
|
rSpeed = 200.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
distance = sensor.distanceCm();
|
||||||
|
duration = random(1000);
|
||||||
|
if (distance>15.0){
|
||||||
|
leftRotor.run(lSpeed);
|
||||||
|
rightRotor.run(rSpeed);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Side = random(2);
|
||||||
|
if (Side == 0){
|
||||||
|
leftRotor.run(lSpeed);
|
||||||
|
rightRotor.run(-rSpeed);
|
||||||
|
}
|
||||||
|
if (Side == 1){
|
||||||
|
leftRotor.run(-lSpeed);
|
||||||
|
rightRotor.run(rSpeed);
|
||||||
|
}
|
||||||
|
delay(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue