Pages: [1]   Go Down
Author Topic: Odd Behavior  (Read 364 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, this is the code:

Code:
/*
  Send numbers to serial out
*/

void setup()
{
  Serial.begin(9600);
  // wait for any serial activity to start
  while (!Serial.available())
  {
  }
  // then send a comma separated file of x,y data
  for (byte i=0;i<256;i++)
  {
     Serial.print(i,DEC);
     Serial.print(',');
     Serial.println(random(0,255),DEC);
  }
}

void loop()
{
 
}

I enter a character, it starts as expected but never stops.  It runs over and over like it was in the loop section instead of the setup section.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem comes because the byte data type can only hold a number from 0 to 255. When it reaches 255, it rolls over to 0, and so never becomes 256 and as a result the loop will never stop.
« Last Edit: August 02, 2010, 04:10:59 pm by programmer » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how stupid of me - thanks!
Logged

Pages: [1]   Go Up
Jump to: