Serial Monitor

hello,

for school we must make a robot that can ride to some random coordinates in a grid , every cube get his own coordinates (xA-xC and yA-yE) and every coord has his own value ( like xA=0, xB=75 , ... ). i would like to enter the coords in the serial monitor and then the value of that coord is given to another variable. some example :

xB = 75

then you give xB in into the serial monitor --> then the value is given to the variable Xvalue

i hope someone can help me

my english is not so good , i am belgian :confused:

this is my code :

int rijden;
int Speed=250;
int SpeedM2=200;

 int L298_ENA = A2;
 int L298_ENB = A3;


 int L298_IN1 = 9;
 int L298_IN2 = 8;
 int L298_IN3 = 7;                                                                                                        //1 vakje is +-75
 int L298_IN4 = 6;

  int teller;
  const int interrupt0pin = 3;

  int A;
  int B;
  int xC;
  int yA;
  int yB;
  int yC;
  int yD;
  int yE;
  int Xwaarde;
  int Ywaarde;


void setup() {
  


 //Motor sturing

Serial.begin(9600);
pinMode(L298_ENA, OUTPUT);
pinMode(L298_IN1, OUTPUT);
pinMode(L298_IN2, OUTPUT);

attachInterrupt(digitalPinToInterrupt(interrupt0pin),pin_ISR, RISING);
}

void loop() {

Xwaarde=0;
Ywaarde=0;


Serial.println("coordinaat X ?");
while(Serial.available()==0) {
  char X = Serial.read();
 
  if (X==A) { Xwaarde = 0;}
  
  if (X==B) { Xwaarde = 70;}
  
  }

//test









Serial.println(Xwaarde);

Serial.println("coordinaat Y ?");
while(Serial.available()==0) {}
Ywaarde=Serial.parseInt();
Serial.println(Ywaarde);

delay(15000);

teller = 0;

while(Xwaarde>teller) { 
  
  //Serial.println(Xwaarde);
  //Serial.println(teller);
    digitalWrite(L298_IN1, HIGH); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, HIGH); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, SpeedM2);   
    
    }

    
    digitalWrite(L298_IN1, LOW); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, LOW); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, SpeedM2);   

   delay(3000);

    digitalWrite(L298_IN1, LOW); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, HIGH); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, SpeedM2);   

      delay(500);
      
     digitalWrite(L298_IN1, LOW); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, LOW); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, SpeedM2);   



    delay(3000);
// Ywaarde

teller = 0;
while(Ywaarde>teller) { 
  
  //Serial.println(Ywaarde);
  //Serial.println(teller);
    digitalWrite(L298_IN1, HIGH); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, HIGH); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, Speed);   
    
    }

    
    digitalWrite(L298_IN1, LOW); 

    digitalWrite(L298_IN2, LOW);  

    analogWrite(L298_ENA, Speed);   

    digitalWrite(L298_IN3, LOW); 

    digitalWrite(L298_IN4, LOW);  

    analogWrite(L298_ENB, Speed);   

  

}
void pin_ISR() {
  
  teller = teller + 1;

// made by GeylianL ; ))

You have a lot of program and you have not explained how it is supposed to work. For example what is the Interrupt for?

If you want a responsive program you need to get rid of ALL the delay()s and probably also any WHILE or FOR that takes more than a few microseconds to complete. Have a look at how millis() is used to manage timing without blocking in Several things at a time

I am not clear about what data you want to send from the Serial Monitor, and what the Arduino should do with it when it receives it. For example do you plan to type "xB" in the Serial Monitor and when the Arduino receives that it should put the value 75 into some variable?

For receiving data and parsing it have a look at Serial Input Basics. I recommend that you don't use Serial.parseInt() because that is a blocking function that could slow things down.

...R