int LeftMotorForward = 6; int LeftMotorReverse = 7; int RightMotorForward = 8; int RightMotorReverse = 9; const int sensorPin0 = A0; // pin that the sensor is attached to const int sensorPin1 = A1; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to // variables: int sensorValue0 = 0; // the sensor value int sensorMin0 = 1023; // minimum sensor value int sensorMax0 = 0; // maximum sensor value int sensorValue1 = 0; // the sensor value int sensorMin1 = 1023; // minimum sensor value int sensorMax1 = 0; // maximum sensor value void setup() { pinMode(LeftMotorForward, OUTPUT); pinMode(LeftMotorReverse, OUTPUT); pinMode(RightMotorForward, OUTPUT); pinMode(RightMotorReverse, OUTPUT); // turn on LED to signal the start of the calibration period: pinMode(13, OUTPUT); digitalWrite(13, HIGH); ////// calibrate during the first five seconds //////////////// while (millis() < 5000) { sensorValue0 = analogRead(sensorPin0); sensorValue1 = analogRead(sensorPin1); // record the maximum sensor value if (sensorValue0 > sensorMax0) { sensorMax0 = sensorValue0; } // record the minimum sensor value if (sensorValue0 < sensorMin0) { sensorMin0 = sensorValue0; } // record the maximum sensor value if (sensorValue1 > sensorMax1) { sensorMax1 = sensorValue1; } // record the minimum sensor value if (sensorValue1 < sensorMin1) { sensorMin1 = sensorValue1; } }//Ende while digitalWrite(13, LOW); }//Ende Setup void loop() { //////////////////// A0 ////////////////////////////////////// // read the sensor: sensorValue0 = analogRead(sensorPin0); // apply the calibration to the sensor reading sensorValue0 = map(sensorValue0, sensorMin0, sensorMax0, 0, 255); // in case the sensor value is outside the range seen during calibration sensorValue0 = constrain(sensorValue0, 0, 255); //////////////////////// A1 ////////////////////////////////// // read the sensor: sensorValue1 = analogRead(sensorPin1); // apply the calibration to the sensor reading sensorValue1 = map(sensorValue1, sensorMin1, sensorMax1, 0, 255); // in case the sensor value is outside the range seen during calibration sensorValue1 = constrain(sensorValue1, 0, 255); //////////////////////////////////////////////////////////////////// vor(); if (sensorValue0 > 150) { //dunkel stoppen(); rechts(); stoppen(); } if (sensorValue1 > 150) { //dunkel stoppen(); links(); stoppen(); } delay(50); }// Ende Loop ///////////// Subroutinen //////////////////// void stoppen(){ digitalWrite(LeftMotorForward, LOW); digitalWrite(LeftMotorReverse, LOW); digitalWrite(RightMotorForward, LOW); digitalWrite(RightMotorReverse, LOW); } void rechts(){ digitalWrite(RightMotorForward, HIGH); digitalWrite(LeftMotorReverse, HIGH); delay(150); digitalWrite(RightMotorForward,LOW); digitalWrite(LeftMotorReverse, LOW); } void links(){ digitalWrite(LeftMotorForward, HIGH); digitalWrite(RightMotorReverse, HIGH); delay(150); digitalWrite(LeftMotorForward,LOW); digitalWrite(RightMotorReverse, LOW); } void vor(){ digitalWrite(RightMotorForward, HIGH); digitalWrite(LeftMotorForward, HIGH); } void zurueck(){ digitalWrite(RightMotorReverse, HIGH); digitalWrite(LeftMotorReverse, HIGH); }