Roboter
const int VCC = 19;
const int GND = 16;
const int echo = 17;
const int triger = 18;
const int v = 9; // links v
const int s = 10;// rechts h
const int w = 11;// rechts v
const int g = 12;// links h
int gesch = 235;
int geschi = 210;
int sp = 250;
float cm ;
void setup () {
Serial.begin(9600);
pinMode(triger,OUTPUT);
pinMode(echo,INPUT);
pinMode(VCC,OUTPUT);
pinMode(GND,OUTPUT);
analogWrite(VCC,255);
digitalWrite(GND,LOW);
pinMode(v,OUTPUT);
pinMode(s,OUTPUT);
pinMode(w,OUTPUT);
pinMode(g,OUTPUT);
}
void linksdrehen (int geschi) {
digitalWrite(v,LOW);
digitalWrite(s,LOW);
analogWrite(g,geschi);
analogWrite(w,geschi);
}
void rechtsdrehen ( int geschi) {
analogWrite(v,geschi);
analogWrite(s,geschi);
digitalWrite(g,LOW);
digitalWrite(w,LOW);
}
void halb (int sp) {
digitalWrite(v,LOW);
digitalWrite(s,LOW);
analogWrite(g,sp);
analogWrite(w,sp);
}
void vorwaerts (int gesch,int geschii) {
analogWrite(w,gesch);
analogWrite(v,sp);
digitalWrite(g,LOW);
digitalWrite(s,LOW);
}
void Stop () {
digitalWrite(s,LOW);
digitalWrite(v,LOW);
digitalWrite(w,LOW);
digitalWrite(g,LOW);
}
void rueckwaerts (int gesch) {
analogWrite(s,gesch);
analogWrite(g,gesch);
digitalWrite(w,LOW);
digitalWrite(v,LOW);
}
void loop () {
digitalWrite(triger, LOW);
delayMicroseconds(2);
digitalWrite(triger, HIGH);
delayMicroseconds(10);
digitalWrite(triger, LOW);
cm = pulseIn(echo, HIGH) / 58.0;
cm = (int(cm * 100.0)) / 100.0;
/* Serial.print(cm);
Serial.print("cm");
Serial.println();*/
delay(500);
if (cm < 15.0) {
rueckwaerts(gesch);
delay(100);
Stop ();
delay(1000);
} else {
vorwaerts(gesch,sp);
/*delay(1000);
Stop();
delay(2000);
rueckwaerts(gesch);
delay(1000);
Stop();
delay(2000);
rechtsdrehen(geschi);
delay(1000);
Stop();
delay(2000);
vorwaerts(gesch,sp);
delay(1000);
Stop();
delay(2000);
linksdrehen(geschi);
delay(1000);
Stop();
delay(2000);
halb (sp);
delay(1200);
Stop();
delay(3000);*/
}
}
Erstellt: Robin Strahlendorf (07.04.2014)
Letzte Änderung: Robin Strahlendorf (07.04.2014)