modified dimmer program

Hi guys,

Just got my Duemilanonve board a couple of days ago and super new to the forums. This looked like the correct place to post this, if not, just let me know. I run OSX 10.5 on an intel Macbook Pro if it matters.

So, I have modified the dimmer program to accept input from the serial port using the serial monitor with some code I grabbed from somewhere else to accept input (sorry can't remember where I got it). I use the Serial Monitor in the Arduino IDE to talk to the Arduino.

Anyway, for this to work properly, it needs a Serial.println("Something"); in the while loop, otherwise the input seems to be read in pieces. Any ideas why this might be the case?

int ledPin = 9;
char incoming; // incoming serial data
int outboundLength = 3;
char outbound[3];
int i=0;
int a = 0;

void setup()
{
// begin the serial communication
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop()
{
i=0; // reset the array index

//to set the array to all 000
for (a = 0; a < outboundLength ; a ++){
outbound[a] = 0;
}

while (Serial.available()) {
incoming = Serial.read();
if (incoming == 64) break; // escape character is @
if ((incoming < 48) or (incoming > 57)) break; // discard non-numerics
outbound*=incoming; //copy the serial byte to the array*

  • Serial.println("Something"); //seems to need this to work properly*

  • i++; // increase the array index*

  • }*

  • if (i !=0) {*

  • Serial.println(outbound); //if the array is not zero, there is data*

  • analogWrite(ledPin, atoi(outbound));*

  • }*
    *} *