i wrote some code for my project that can enable 2 mode for control the object, Automatic and Manual. im using bluetooth as a serial monitor that can use as a transfer data. this is my program :
void setup() {
monServo.attach(10);
monServo.write(90);
delay(2000);
Serial.begin (38400);
mySerial.begin (38400);
pinMode (2, OUTPUT);
pinMode (4, OUTPUT);
pinMode (10, OUTPUT);
}
void loop ()
{
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 'a')
{Serial.println ("Otomatis");
void otomatis();}
else if (incomingByte == 'b')
{Serial.println ("Manual");
void manual();}}
}
void otomatis () {
int us1 = sonar1.ping_cm();
int us2 = sonar2.ping_cm();
Serial.print (us1);
Serial.print (" cm ");
Serial.print (" and ");
Serial.print (us2);
Serial.println (" cm ");
delay (50);
if ( us1 >= 50 && us2 >= 30)
{Serial.println ("MAJU");
digitalWrite(dir1, HIGH);
analogWrite(a1, 10);
digitalWrite(dir2, HIGH);
analogWrite(a2, 10);}
else if ( us1 <= 50 && us2 >= 30)
{ Serial.println ("KIRI");
digitalWrite(dir1, HIGH);
analogWrite(a1, 200);
digitalWrite(dir2, HIGH);
analogWrite(a2, 20);}
}
void manual () {
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'A') {
Serial.println ("Go");
digitalWrite(dir1, HIGH);
analogWrite(a1, 70);
digitalWrite(dir2, HIGH);
analogWrite(a2, 70);}
else if (incomingByte == 'B') {
Serial.println ("Left");
digitalWrite(dir1, HIGH);
analogWrite(a1, 200);
digitalWrite(dir2, HIGH);
analogWrite(a2, 20);}
else if (incomingByte == 'C') {
Serial.println ("Back");
digitalWrite(dir1, LOW);
analogWrite(a1, 180);
digitalWrite(dir2, LOW);
analogWrite(a2, 180);}
else if (incomingByte == 'D') {
Serial.println ("Stop");
digitalWrite(dir1, LOW);
analogWrite(a1, 0);
digitalWrite(dir2, LOW);
analogWrite(a2, 0);}
else if (incomingByte == 'E')
{ Serial.println ("Turn Right");
monServo.write(30);}
else if (incomingByte == 'F')
{ Serial.println ("Turn Left");
monServo.write(180);}
else if (incomingByte == 'a')
{ Serial.println ("Automatic");
void otomatis();}
}
}
no error while im compiling this,
but when i run this there no restponse
can anyone help me