Manual
www.nexusrobot.com Robot Kits manual
124
analogWrite(MOTOR1_E, 48); // stop the motor1
analogWrite(MOTOR2_E, 44); // stop the motor2
analogWrite(MOTOR3_E, 46); // stop the motor3
}
//*************************************************//
void (*motion[8])()={ goAhead,RotateLeft,turnRight,RotateLeft,turnLeft,RotateLeft,judge,allStop};
//change the
void demowithSosars(){
unsigned char sonarcurrent=0;
if(millis()-currMillis>SONAR::duration){ //judge if the time more than SONAR::duration;
currMillis=millis();
sonarcurrent= sonarUpdate(); //if the requirement was ture call the function;
}
if(sonarcurrent==3){
unsigned char bitmap = (distBuf[0] < 20);//front
bitmap |= (distBuf[1]<20) <<1; //left
bitmap |= (distBuf[2]<20) <<2; //right
Serial.print("bitmap=");
Serial.println(bitmap,DEC);
(*motion[bitmap])();
}
}
//*************************************************//
void setup() {
TCCR1B=TCCR1B&0xf8|0x04;
TCCR2B=TCCR2B&0xf8|0x06;
pinMode(MOTOR1_E, OUTPUT);
pinMode(MOTOR2_E, OUTPUT);
pinMode(MOTOR3_E, OUTPUT);
SONAR::init(); //call the init() from SONAR.h;
delay(2000);
Serial.begin(19200);
}
void loop(){
demowithSosars();
//delay(200);
}