Page 46 - 2
P. 46
/*************************** 오른쪽*****************************/
//If state is equal with letter 'R', wheels will turn right
else if (state == 'R') {
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
//analogWrite(motorB1, 0); analogWrite(motorB2, -100);
myservo.write(0);
}
/************************ 헤드라이트 백라이트, *****************************/
//If state is equal with letter 'W', turn leds on or of off
else if (state == 'W') {
if (i==0){
digitalWrite(lights, HIGH);
i=1;
}
else if (i==1){
digitalWrite(lights, LOW);
i=0;
}
state='n';
}
/********************** 부저 사운드***************************/
//If state is equal with letter 'V', play (or stop) horn sound
else if (state == 'V'){
if (j==0){
tone(buzzer, 1000);//Speaker on
j=1;
}
else if (j==1){
noTone(buzzer); //Speaker off
j=0;
}
state='n';
}
/************************ 정지*****************************/
//If state is equal with letter 'S', stop the car
else if (state == 'S'){
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 0);
}
/***********************Battery*****************************/
//Read battery voltage every 10sec.
currentMillis = millis();
if(currentMillis - (previousMillis) > (interval)) {
previousMillis = currentMillis;
- 46 -