Count 18 lines and pause.

The problem I’m having is counting 18 lines of data, each line contains 6 values and pausing to read results after the 18th line has been displayed, before pressing key to then display the next 18 lines ``long randNumber; int count = 18;

void setup() { Serial.begin(9600); randomSeed(analogRead(0)); }

void loop() {

{ count = 0; } { randNumber = random(1, 45); Serial.print(randNumber); Serial.print(",");

randNumber = random(1, 45); Serial.print(randNumber); Serial.print(",");

randNumber = random(1, 45); Serial.print(randNumber); Serial.print(",");

randNumber = random(1, 45); Serial.print(randNumber); Serial.print(",");

randNumber = random(1, 45); Serial.print(randNumber); Serial.print(",");

randNumber = random(1, 45); Serial.println(randNumber); delay(1000);

{ Serial.println(" End of Block"); } } }

I don't know for certain what you want. Right now you print 6 random numbers and repeat. Does this mean a line and you want 18 lines of 6 numbers each line, then pause for serial input?

What is your counter doing?

It needs to count 18 line of 6 values then wait so values can be read, then press a button and display another 18 lines of 6 values and pause, etc etc.

click the MODIFY button in the upper right of the post window. Highlight all you code. click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button. click SAVE (at the bottom). When you post code on the forum, please make a habit of using the code tags "#" button.

Did you post the whole program or just a part of it ?

When you talk about pressing a key, is this a key on the PC keyboard, or a pushbutton switch connected to the Arduino?

Whole, it's the coding of the counting of the 18 lines that is not working, I have tried "If", "For", "Else" to count the 18 lines to get to the "End of Block" text, I must not have enough knowledge of Arduino coding at the moment.

On the Arduino at the moment.

OK, set the button press requirement aside, and try just taking a character from the serial port for simplicity so you can understand how to get the counter to work.

The way you set it up, the variable counter is not doing anything. If you always print 18 lines of 6 numbers, you should use a for loop.

http://arduino.cc/en/Reference/For

The above example code shows how to do something 256 times. You can use this as a template. Then at the end of your loop() function, before you close the "}", add while(1){} to stop the execution. You will see 18 lines and then stop. This is your step one, get 18 lines and stop.

Your next step is to replace the while(1){} with something that can make the code run again for 18 lines. Replace it with

while(1)
{
  if(Serial.available())
  {
    Serial.read();
    break;
  }
}

In that case your problem can be solved by putting in code to wait until a key press occurs. Assuming you have a switch wired up correctly to a digital input, that just needs a while loop that calls digitalRead() repeatedly until the result indicates that a keypress has occurred.

Replace it with

Why? Loop will run over and over. An infinite loop inside an infinite loop() just looks stupid.

I thank you all for your help but it still does not help in the problem of coding of the counting of 18 lines while the number loop is working. I have tried using the various codings to perform the counting loop with out any success, all I have been able to achieve is for the count coding is to drop through to the code for "end of block" and one line of values then repetitive lines of "end of block" code. I need help in fixing this problem.

Can you provide an example of what you're trying to achieve?

HazardsMind: Can you provide an example of what you're trying to achieve?

I thought OP just wants to print 18 lines of random numbers and pause for input. I posted how to use for loop. Can't be easier than that, since 18 is a fixed magic number.

I used your coding and could not get it to do what I wanted, I may have inserted the coding wrong but I don't think so. All I get is one line of 5 values and then "end of block" on same line, then it repeats as before down the page not stopping at 18 lines as required. I thank you for your help and time on my problem..

I used your coding

...but you didn't post it.

author=JQuinn link=topic=231938.msg1672044#msg1672044 date=1397019859]
The problem I’m having is counting 18 lines of data, each line contains 6 values
and pausing to read results after the 18th line has been displayed, before pressing key to then display the next 18 lines

long randNumber;
int count=0;



void setup(){
  Serial.begin(9600);

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 1 to 45
  // my code
  
  randNumber = random(1, 45);
    Serial.print(randNumber);  
    Serial.print(",");
    
     randNumber = random(1, 45);
      Serial.print(randNumber);  
      Serial.print(",");
      
       randNumber = random(1, 45);
        Serial.print(randNumber);  
        Serial.print(",");
        
 randNumber = random(1, 45);
  Serial.print(randNumber);  
    Serial.print(",");
    
     randNumber = random(1, 45);
      Serial.print(randNumber);  
      Serial.print(",");
      
    randNumber = random(1, 45);
  Serial.println(randNumber);
      delay(1000);
      
  // added code    
  while(1)
{
  if(Serial.available())
  {
    Serial.read();
    break;
 }
  }
   }

Moderator edit: Untangled tags

The problem I’m having is counting 18 lines of data, each line contains 6 values

Could be, since you are not counting anything.

Correct, it only prints one line of values.
What I have been trying is to get 18 lines printed and for coding to drop program through to say end of block, and to wait for the next action, something along the lines

" for (count==18); Serial.print(“End of Block”) "

and wait for values to be read and then to start again with some other action.

What I have been trying is to get 18 lines printed

That is NEVER going to happen until you start counting. There are a variety of ways to do that - for statements, while statements, or a combination of if and ++.

something along the lines " for (count==18); Serial.print("End of Block") "

The quotes are wrong. The for statement is wrong (should be if). The ; in the middle of the line belongs on the end AND you need to define, and, at appropriate times increment or reset, count.

and then to start again with some other action.

Start what again? What other action?