Ro,Ro und He
int MotorR_v=10;
int MotorR_r=11;
int MotorL_v=5;
int MotorL_r=6;
int potti = A0;
int v = 255;
int pottiwert =0;
int trigPin=9;
int echoPin=8;
long duration;
float distance;
void setup() {
Serial.begin(9600);
pinMode(potti, INPUT);
pinMode(MotorR_v, OUTPUT);
pinMode(MotorR_r, OUTPUT);
pinMode(MotorL_v, OUTPUT);
pinMode(MotorL_r, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop(){
/* potiwert = analogRead(potti);
int vR = pottiwert/4;*/
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration/58.2*10;
Serial.println(distance);
delay(50);
if(distance<300){
analogWrite(MotorR_v, 255);
analogWrite(MotorL_v, 255);
}
else{
analogWrite(MotorR_v, 0);
analogWrite(MotorL_v, 100);
analogWrite(MotorR_r, 100);
analogWrite(MotorL_r, 0);
}
}
Ziel für heute und nächste Woche: Rädergeschwindigkeit gleichschalten