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
}
3 Answers 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– James Waldby - jwpat72015年09月18日 01:03:09 +00:00Commented Sep 18, 2015 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– MANSOR2015年09月18日 05:14:18 +00:00Commented Sep 18, 2015 at 5:14
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– MANSOR2015年09月16日 07:32:10 +00:00Commented Sep 16, 2015 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 said100
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 afor
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.2015年09月16日 21:35:35 +00:00Commented Sep 16, 2015 at 21:35 -
Nick, where you say
int main ()
, was that intentional, or did you mean to havevoid setup()
?James Waldby - jwpat7– James Waldby - jwpat72015年09月17日 00:23:07 +00:00Commented Sep 17, 2015 at 0:23 -
It was intentional in the spirit of keeping it "short". Doing a
main
means you don't need bothsetup
andloop
, and is more in-line with standard C programming. You do, of course, need to also callinit()
if you expect to use timers,delay()
and so on.2015年09月17日 00:48:22 +00:00Commented Sep 17, 2015 at 0:48 -
1It worked when I tested it. In what way does it not work for you? Compiler error? Wrong numbers shown? No numbers? Please be specific.2015年09月17日 20:47:00 +00:00Commented Sep 17, 2015 at 20:47
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.
The faster the better
- how about 115200 baud then?