Code:
int rforward = 13;
int rreverse = 12;
int lforward = 5;
int lreverse = 4;
int lmotorspeed = 255;
int lmotor= 9;
int rmotorspeed = 255;
int rmotor= 10;
int statusledred = 2;
int frontled = 6;
int lphotores = 3;
int rphotores = 2;
int statusledgreen = 8;
int odometricled = 7;
long tmp;
long taster = ((10240000L/tmp-10000L)*61L+5000L)/10000;
void setup()
{
pinMode(rforward, OUTPUT);
pinMode(rreverse, OUTPUT);
pinMode(lforward, OUTPUT);
pinMode(lreverse, OUTPUT);
pinMode(frontled, OUTPUT);
pinMode(statusledred, OUTPUT);
pinMode(statusledgreen, OUTPUT);
pinMode(odometricled, OUTPUT);
}
//read front switches
int readSwitches()
{
long taster = ((10240000L/tmp-10000L)*61L+5000L)/10000; // Pollswitch-Funktion Tasterauswerutng
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
tmp = analogRead(4);
digitalWrite(3, LOW);
return taster;
}
void loop()
{
readSwitches();
//GERADAUS FAHREN 2500ms
digitalWrite (4, LOW); //Links vorwärts
digitalWrite (5, HIGH);
digitalWrite (9,HIGH);
digitalWrite (12, LOW); //Rechts vorwärts
digitalWrite (13, HIGH);
digitalWrite(10,HIGH);
if (taster == 2 || taster ==4 || taster == 8 || taster ==16 || taster ==32);
{
//RÜCKWÄRTSFAHREN
// linker Motor zurück
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
digitalWrite(9,HIGH);
// rechter Motor zurück
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(10,HIGH);
delay(2500);
// 90 GRAD LINKSKURVE
//Rechts vorwärts
digitalWrite (12, LOW);
digitalWrite (13, HIGH);
digitalWrite(10,HIGH);
// links zurück
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(2500);
//GERADAUS FAHREN 2500ms
digitalWrite (4, LOW); //Links vorwärts
digitalWrite (5, HIGH);
digitalWrite (9,HIGH);
digitalWrite (12, LOW); //Rechts vorwärts
digitalWrite (13, HIGH);
digitalWrite(10,HIGH);
delay(2500);
//90 GRAD RECHTSKURVE
digitalWrite (4, LOW); //Links vorwärts
digitalWrite (5, HIGH);
digitalWrite (9,HIGH);
// Rechts rückwärts
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(10,HIGH);
delay(2500);
}
}
Hieran haben wir uns orientiert und es auch so angewendet :
Lesezeichen