0

Could someone help me how to output the numbers from 1 to 10 via Serial, without having to write out each command by hand?

Below is my sketch - I need it concise instead of a long sketch:

#include <Streaming.h
//setup
void setup() {
 Serial. begin(9600);//The faster the better
}//Close the sertup

//main loop 
void loop() { 

  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(1) << endl;
  delay(1000);
  Serial<< _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(2) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(3) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(4) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(5) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(6) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(7) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(8) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(9) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(10) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(11) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(12) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(13) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(14) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(15) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(16) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(17) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(18) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(19) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(20) << endl;
   delay(1000);
  while(1){}//freeze the main loop

}  
  • Where is the photo? – Nick Gammon Sep 16 '15 at 6:18
  • 1
    It is better to post the code, not photograph a screen with it on. Just copy the code from your sketch, edit your post, and post it into it. Select the code and hit Ctrl+K to indent it, and make it look nice. – Nick Gammon Sep 16 '15 at 6:28
  • The faster the better - how about 115200 baud then? – Nick Gammon Sep 16 '15 at 6:30
  • Can you tell me how to add my code here? – MANSOR Sep 17 '15 at 5:23
  • 1
    Edit your question (Click "edit"). Copy the code from your sketch and paste it into the question. Then select the code and hit Ctrl+K to indent it and make it look like code. – Nick Gammon Sep 17 '15 at 5:41
3

[This replaces my earlier answer, and addresses information added to the question.]

You apparently want a sketch that outputs 1, 2, 3 ... 100 to serial output, where each number string is embedded within a control sequence.

Here are two ways. The first program outputs the sequence once, using ordinary Arduino Serial.write(), Serial.print() and Serial.println() statements:

Program 1. Output 1, 2, 3 ... 100 once

void setup() {
  Serial.begin(9600);
  for (int j=1; j<=100; ++j) {
    Serial.write(27); // Send escape character
    Serial.print("[2J"); // Send erase-screen command
    Serial.print("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t");
    Serial.println(j); // Send j in decimal format
    delay(1000);
  }
}
void loop() {}

The other program will output the sequence repeatedly. It uses the Streaming.h library, but in a rational manner; for example, instead of quoting every character separately like the program in the photo, it quotes character sequences in strings. Note, Esc [2J is an ANSI escape code sequence that erases the screen it is directed to, if the screen device is ANSI compliant.

Program 2. Output 1, 2, 3 ... 100 repeatedly

#include <Streaming.h> // or "Streaming.h" if appropriate
byte j=0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  ++j;
  // Send Esc [2J which will erase screen
  Serial << _BYTE(27) << "[2J";
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << j;
  if (j >= 100) j=0;
  delay(1000);
}
  • Yasir, I added a } that was missing, and also added delay(1000);. When you say “I have tried many time to use your code but it doesn't work” are you referring to Nick's code, or to one of my programs above? What happens when you compile and upload the code? – James Waldby - jwpat7 Sep 18 '15 at 1:03
  • Thank you so so much I really appreciate your help, I have just copy your code and it works very well.;-) – MANSOR Sep 18 '15 at 5:14
3

Ah, a challenge!

I have to write from 1 to 100, and I don't want to repeat it all 100 times

Your question did not make that clear. Anyway:

int main () { 
  Serial.begin (9600); 
  for (int i = 1; i <= 100; i++) 
    Serial.println (i); 
  while (true); 
  }

You can probably make it shorter at the expense of readability.

int main(){Serial.begin(9600);for(int i=1;i<=100;i++)Serial.println(i);while(1);}
  • Ah, a challenge! I have to write from 1 to 100, and I don't want to repeat it all 100 times Your question did not make that clear. Anyway: int main () { Serial.begin (9600); for (int i = 1; i <= 100; i++) Serial.println (i); while (true); } You can probably make it shorter at the expense of readability. int main(){Serial.begin(9600);for(int i=1;i<=100;i++)Serial.println(i);while(1);}. If I use this way, the number will count automatically from 1 to 10 ? – MANSOR Sep 16 '15 at 7:32
  • You don't need to copy and paste my entire answer into your comment. That is just very confusing. If I use this way, the number will count automatically from 1 to 10 - well you said 100 in your comment ("I have to write from 1 to 100"). Try to pay attention when you are typing. Asking for 10/100/10 is really confusing. Yes, that is what a for loop does. You may want to read a tutorial on C programming. Copying and pasting 100 times is not what your teacher had in mind, I bet. – Nick Gammon Sep 16 '15 at 21:35
  • Nick, where you say int main (), was that intentional, or did you mean to have void setup() ? – James Waldby - jwpat7 Sep 17 '15 at 0:23
  • It was intentional in the spirit of keeping it "short". Doing a main means you don't need both setup and loop, and is more in-line with standard C programming. You do, of course, need to also call init() if you expect to use timers, delay() and so on. – Nick Gammon Sep 17 '15 at 0:48
  • 1
    It worked when I tested it. In what way does it not work for you? Compiler error? Wrong numbers shown? No numbers? Please be specific. – Nick Gammon Sep 17 '15 at 20:47
2

Fixing the typos in your original code, so that it should probably read:

#include <Streaming.h>

//setup
void setup() {
 Serial.begin(9600);  //The faster the better
}   //Close the setup

//main loop 
void loop() { 
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(1) << endl;
  delay(1000);
  Serial<< _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(2) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(3) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(4) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(5) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(6) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(7) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(8) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(9) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(10) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(11) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(12) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(13) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(14) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(15) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(16) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(17) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(18) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(19) << endl;
  delay(1000);
  Serial << _BYTE(27)<< _BYTE(91)<< _BYTE(50)<< _BYTE(74);//CLR
  Serial<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<<"\n"<< endl;
  Serial<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<< _DEC(20) << endl;
  delay(1000);
  while(1){} //freeze the main loop
}  

Then condensing the cursor positioning lines, gives:

#include <Streaming.h>

//setup
void setup() {
 Serial.begin(9600);  //The faster the better
}   //Close the setup

//main loop 
void loop() { 
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(1) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(2) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(3) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(4) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(5) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(6) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(7) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(8) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(9) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(10) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(11) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(12) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(13) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(14) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(15) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(16) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(17) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(18) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(19) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n" << endl;
  Serial << "\t\t\t\t\t" << _DEC(20) << endl;
  delay(1000);
  while(1){} //freeze the main loop
}  

Then joining the two cursor positioning lines, gives:

#include <Streaming.h>

//setup
void setup() {
 Serial.begin(9600);  //The faster the better
}   //Close the setup

//main loop 
void loop() { 
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(1) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(2) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(3) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(4) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(5) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(6) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(7) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(8) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(9) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(10) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(11) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(12) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(13) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(14) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(15) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(16) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(17) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(18) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(19) << endl;
  delay(1000);
  Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
  Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(20) << endl;
  delay(1000);
  while(1){} //freeze the main loop
}  

Then putting each repeated line in a for loop, and adding a Maximum Count const variable, gives:

#include <Streaming.h>

const int MaxCount = 20;

//setup
void setup() {
 Serial.begin(9600);  //The faster the better
}   //Close the setup

//main loop 
void loop() { 
  for (int n = 1; n < 20; n++) {
    Serial << _BYTE(27) << _BYTE(91) << _BYTE(50) << _BYTE(74); //CLR
    Serial << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t" << _DEC(n) << endl;
    delay(1000);
  }

  while(1){} //freeze the main loop
}  

However, jwpat7's answer is much better, and Nick's answer is the shortest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.