Serial.read() array?

Hey all,
I am working on a project where I need to send a number of values from my mac to the Arduino. My question is, is it possible to send and receive arrays?

Thanks,
-Korki

Yes, look at "for" loops.

My question is, is it possible to send and receive arrays?

Sure, but it always arrives one byte at a time. You have to pack your array in a loop. So it gets a little more complex then you might like. Your Arduino code needs to know how many bytes will be coming down and to make sure that your array is large enough to hold them, also you need to know when one stream of received bytes starts and ends so as to not overlap old data with new data. Basically you need to use a serial protocol, either one you design yourself or some some pre-existing library code.

Lefty

Ok so I got this working but I have another question is there a way to check if USB is plugged in? In the final project the Arduino will be running off of external power and I want to check if a USB cable is plugged in. If one is wait for data. otherwise do something else.

Thanks
-Korki

Ok so I got this working but I have another question is there a way to check if USB is plugged in?

None that I'm aware of. Otherwise just use the normal serial.available command to see if something has arrived or not:

http://arduino.cc/en/Serial/Available

Lefty

I tried serial.available but if nothing is coming at the time it does the other things and thats a problem because it wont be getting constant values.

-Korki

If the program can not run without the serial input, it needs to be stopped and wait for input.

This can be done by using a 'while' statement.

i.e. while(!serial.available) { /* Do Nothing... */ }

And something that I have started to do is put incoming strings in talking marks ("string1" ). That way my program knows when to start recording values and stop recording values.

I hope this helps :)

The project is an LED array. So if no USB is plugged it I want it to run a certain animation. But if one gets plugged in I want the computer to have control.

-Korki