Manual
www.nexusrobot.com Robot Kits manual 
  73
/* 
void loop() { 
 _2WD.demoActions(80,5000); //Call the demoActions from the class 2WD 
} 
 */ 
void loop() { 
 boolean bumperL=!digitalRead(bumperL_pin); // a flag to sure if the Left have someting 
 boolean bumperC=!digitalRead(bumperC_pin); 
 boolean bumperR=!digitalRead(bumperR_pin); 
  int irL0=ir_distance(irL0_pin);      // A variable to save the data of the left Infrared Sensor return 
 int irC0=ir_distance(irC0_pin); 
 int irR0=ir_distance(irR0_pin); 
 static unsigned long currMillis=0; 
 if(millis()-currMillis>SONAR::duration) {    //every 60ms call sonarUpdate() once 
 currMillis=millis(); 
 sonarsUpdate(); 
 } 
 if(bumperL || bumperC || bumperR) { // If the car hit something 
 _2WD.setCarBackoff(speedMMPS); // Set car backoff at the speed of speedMMPS 
 _2WD.delayMS(300);       // last 300 ms  
 if(bumperL || bumperC) _2WD.setCarRotateRight(speedMMPS); // // back off and turn right 
 else _2WD.setCarRotateLeft(speedMMPS); // back off and turn left 
 _2WD.delayMS(300); 
 } else if(0<irL0 && irL0<30 || 0<irC0 && irC0<40 || 0<distBuf[0] && distBuf[0]<30 || 0<distBuf[1] 
&& distBuf[1]<40) {                  // If any of these conditions was ture? 
 _2WD.setCarRotateRight(speedMMPS); // Set car rotateright 
 } else if(0<irR0 && irR0<30 || 0<distBuf[2] && distBuf[2]<30) { 
 _2WD.setCarRotateLeft(speedMMPS); 
 } else {              // The is nothing around the car 
 _2WD.setCarAdvance(speedMMPS); // Set car move advance at the speed of speedPPMS 
 } 
 _2WD.PIDRegulate(); // PID regulate the speed 
} 










