const int enA = 4;
const int enB = 9;
const int Apin = 38;
const int Bpin = 32;
const int Cpin = 50;
const int Dpin = 45;
int trig = 12;
int echo = 11;
long lecture_echo;
long cm;
int x;
char m;
String inputString="";
void setup(){
pinMode(4,OUTPUT);
pinMode(9,OUTPUT);
pinMode(38,OUTPUT);
pinMode(32,OUTPUT);
pinMode(50,OUTPUT);
pinMode(45,OUTPUT);
Serial.begin(9600); // set the baud rate to 9600, same should be of your Serial Monitor
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
pinMode(11, INPUT);
}
void loop(){
x == 0;
if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff
if(inputString == "f"){
do while(x==0){
detobe();
}
}
else if(inputString== "g"){
do while(x==1){
blue();
}
}
inputString = "";
}
void detobe(){
digitalWrite(enA,170);
digitalWrite(enB,170);
digitalWrite(trig, HIGH);
delayMicroseconds(10); // envoi d'une impulsion sur trig de 10 microsecondes
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo, HIGH);
cm = lecture_echo / 58; // lecture_echo340/(210000)
if( cm > 8 )
{
digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
//digitalWrite(ledPin2,HIGH);
//digitalWrite(ledPin1,HIGH);
//delay (2000);
//digitalWrite(ledPin2,HIGH);
//digitalWrite(ledPin1,LOW);
// digitalWrite(Apin,HIGH);
//digitalWrite(Bpin,LOW);
//digitalWrite(Cpin,LOW);
//digitalWrite(Dpin,LOW);
}
else
{
digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
}
if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff
if(inputString == "h"){
x == 1;
}
}
void blue() {
digitalWrite(enA,170);
digitalWrite(enB,170);
if(Serial.available()){
while(Serial.available() )
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ m = Serial.read() ; } // clear the serial buff
if(inputString == "a"){ //in case of 'a' turn the LED on
digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,HIGH);
}else if(inputString == "b"){ //incase of 'b' turn the LED off
digitalWrite(Apin,HIGH);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
}
if(inputString== "c"){
digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,HIGH);
}else if (inputString == "d"){
digitalWrite(Apin,LOW);
digitalWrite(Bpin,HIGH);
digitalWrite(Cpin,HIGH);
digitalWrite(Dpin,LOW);
}
if (inputString== "e" ){
digitalWrite(Apin,LOW);
digitalWrite(Bpin,LOW);
digitalWrite(Cpin,LOW);
digitalWrite(Dpin,LOW);
}
if(inputString == "h"){
x == 1;
}
inputString = "";
}
}
Hello, I am newbie in Arduino and I try to make a robot commended by bluetooth. but I have a problem , when I check the program it tells me that the function is not declared