Issue with function having two arguments - need assistance

Hello Everyone, this is my first attempt in learning to work with Arduino. I do have some programming experience, but not with C++ (ruby, javascript, php), so I found myself on unfamiliar ground.

I fail to understand why my code (below) will refuse to return the second argument complete. In fact, if there wouldn't be a delay between the two Serial.println() calls, it wouldn't even print the first argument completely.

I tried to figure it out using the documentation provided, but couldn't find anything to explain this paranormal behaviour.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
}

void numbers(String txt, int num){
  Serial.println(txt);
  //without delay, it will only print "my" - the first part of the "txt"
  delay(100);
  Serial.println(num);
}

void loop() {
  // put your main code here, to run repeatedly:
  numbers("my text", 180);
  abort();
}

the above prints

my text
18

and I would expect to see:

my text
[b]180[/b]

Any help appreciated.

You forgot a “flush”

The problem is that the abort() function causes the program to stop before all of the data has been printed

Try this

void setup()
{
  Serial.begin(19200);
}

void numbers(String txt, int num)
{
  Serial.println(txt);
  Serial.println(num);
  Serial.flush();  //empty the print buffer before moving on
}

void loop()
{
  numbers("my text", 180);
  abort();

Why are you calling abort() anyway ?

UKHeliBob:
Why are you calling abort() anyway ?

i am learning how to stop a script so it won't run continuously... i just found abort() as a method of stopping, but didn't find much about it. Not sure if is the best method from what it seems....

Thank you for the flush. I will have to document myself about, as I am not used with C++ :smiley:

i am learning how to stop a script so it won’t run continuously

So, put the code in setup.

derei:
i am learning how to stop a script so it won't run continuously

As suggested, put code to run once in setup()

If the program actually has code in loop() but then needs to apparently stop doing anything you can do

while(true);

or

for (;;);

both of which create an endless loop