8
delay(time * 100);
}
void spin_right(int time) //Right rotation
{
digitalWrite(Right_motor_go,LOW); // right motor back off
digitalWrite(Right_motor_back,HIGH);
analogWrite(Right_motor_go,0);
analogWrite(Right_motor_back,200);// PWM--Pulse Width Modulation(0~255) control
speed
digitalWrite(Left_motor_go,HIGH);// left motor go ahead
digitalWrite(Left_motor_back,LOW);
analogWrite(Left_motor_go,200);// PWM--Pulse Width Modulation(0~255) control
speed
analogWrite(Left_motor_back,0);
delay(time * 100);
}
void back(int time) //back off
{
digitalWrite(Right_motor_go,LOW); //right motor back off
digitalWrite(Right_motor_back,HIGH);
analogWrite(Right_motor_go,0);
analogWrite(Right_motor_back,150);// PWM--Pulse Width Modulation(0~255) control
speed
digitalWrite(Left_motor_go,LOW); //left motor back off
digitalWrite(Left_motor_back,HIGH);
analogWrite(Left_motor_go,0);
analogWrite(Left_motor_back,150);// PWM--Pulse Width Modulation(0~255) control
speed
delay(time * 100);
}
void keysacn()
{
int val;
val=digitalRead(key);// Reads the button ,the level value assigns to val
while(digitalRead(key))// When the button is not pressed
{
val=digitalRead(key);
}
while(!digitalRead(key))// When the button is pressed
{
delay(10);
//delay 10ms
val=digitalRead(key);// Reads the button ,the level value assigns to val
if(val==LOW) //Double check the button is pressed
{
digitalWrite(beep,LOW);//The buzzer sounds
delay(100);//delay 100ms
while(!digitalRead(key)) //Determine if the button is released or not
digitalWrite(beep,HIGH);//mute
}
else
digitalWrite(beep,HIGH);//mute
}