Loop the data already received on the serial monitor

Hello there,

i would like you all to help me find the way to loop the data wich is displayed on the serial monitor, that might look like making a loop of the data inserted in the serial monitor...

thanks in advance guys!!!

What does "loop the data" mean?

Respect.

the main idea of the program is to repeat over and over the information received in the serial monitor,
for example:

if the serial monitor receives the data:

12
13
13
14
14

what i would like to do is, get that data and make it loop inside the serial monitor like:

12
13
13
14
14

12
13
13
14
14

12
13
13
14
14

etc

The data received in the serial monitor is generated by the code running on the Arduino (code you haven't shared with us).

What's the problem?

in this bluetooth car control program, the idea is record the movements done by the car with one button and the make the car play the same actions by pressing another button...
let see if you get the idea with the program...

those three buttons are:

REC
PAUSE
PLAYREC

bluetooth_car.ino (1.83 KB)

I'm on a phone.
I can't see the code.

I can’t either. To be honest I have no idea how re printing the same data in the serial moniter will do any kind of car control at all. It there a chance that a huge piece of information is being left out?

#define ENA 5
#define ENB 6
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define LED 13

String readString;
unsigned char carSpeed = 250;
bool state = LOW;
char getstr;

void forward(){
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
Serial.println("Forward");
}

void back(){
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
Serial.println("Back");
}

void left(){
analogWrite(ENA,carSpeed);
analogWrite(ENB,carSpeed);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
Serial.println("Left");
}

void right(){
analogWrite(ENA,carSpeed);
analogWrite(ENB,carSpeed);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
Serial.println("Right");
}

void stop(){
digitalWrite(ENA,LOW);
digitalWrite(ENB,LOW);
Serial.println("Stop!");
}

void stateChange(){
state = !state;
digitalWrite(LED, state);
Serial.println("Light");
}

void record(){
Serial.flush();
}

void pauserec(){

}

void playdata(){

}

void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(ENA,OUTPUT);
pinMode(ENB,OUTPUT);
stop();
}

void loop()
{
getstr = Serial.read();
switch(getstr)
{
case 'f': forward(); break;
case 'b': back(); break;
case 'l': left(); break;
case 'r': right(); break;
case 's': stop(); break;
case 'a': stateChange(); break;
case 'rec': record(); break;
case 'pauserec': pauserec(); break;
case 'play': playdata(); break;
default: break;
}
}

case 'pauserec'Now, that's a big conceptual problem.

I don't see how this badly-posted code relates to reply#4

ARe you suppose to hit a button which then plays that code?

with some variable describing all the information inside the serial monitor everything would be easy!

It wont

ecfelo:
with some variable describing all the information inside the serial monitor everything would be easy!

You mean like an array?
You're absolutely right

AWOL:
You mean like an array?
You're absolutely right

exactly

Just to add my two rubles worth:
I'm almost certain you will want a time element associated with the commands recorded; I'd suggest a two dimensional array as discussed here.

Write to it when your switch case is true AND the global variable recording (bool) = true.

void loop() 
{ 
  if(old_recordingSTATE == false && recording == true){ // set millis() to 0}

  getstr = Serial.read();
  switch(getstr)
  {
    case 'f': forward(); 
     SaveRecordingPath (recording, millis() , getstr);
     break;
   }
old_recordingSTATE  = recording;
}


void SaveRecordingPath (bool isRECORDING, int long TIME, char COMMAND){

   if (isRECORDING == true){
     // write to  array here
    // increase array_slot
    }
    else{
    array_slot = 0;
    }
}