reading serial text back into integers array

hi
I am a newbie and needs help( I tried for more than 6 days but useless).

I have arduino mega + 10 LEDs.( in straight single row)

I have vb.net GUI, from it I want to send 10 LED numbers(1,1,2,1,3,1,4,0,5,1,6,0,7,1,8,0,9,0,10,1) and 10 LED status(may be 1(ON) or 0(OFF)) like this :

LED_1,LED_1_staus, LED_2,LED_2_staus,LED_3,LED_3_staus,…… LED_10,LED_10_staus
Here is vb.net code

Dim dataToSend As String
dataToSend = "1,0,2,1,3,1,4,1,5,0,6,0,7,0,8,1,9,1,10,0"

Try
If SerialPort1.IsOpen Then

SerialPort1.WriteLine(dataToSend)

SerialPort1.Close()
Else
SerialPort1.Open()
SerialPort1.WriteLine(dataToSend)
SerialPort1.Close()
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try

=======================================
Now I have arduino code problem to read back these values and put them into int (integer ) array to power LEDs ON or OFF on specific pattern
Any help please

I want to send 10 LED numbers(0,1,2,3,4,5,6,7,8,9,10)

0 to 10 is 11 values.

Now I have arduino code problem to read back these values

The problem is?

how I read from arduino the values and put them into array?

how I read from arduino the values and put them into array?

First, you need to send delimited data, not what you are sending now.

dataToSend = "<1,0,2,1,3,1,4,1,5,0,6,0,7,0,8,1,9,1,10,0>"

Then, you need to read the serial data, as it comes in. You need to take one action if the character is '<', another if the character is '>', and another if the character is anything else.

You need an array to store the data in, and an index variable to define where to store the data.

So, you try something, and we'll help you get it right.

If you send the data as @PaulS has suggested you can receive it with the 3rd example in serial input basics. There is also a parse example.

...R

Thanks a lot and very appreciated, you people making the world nicer :slight_smile: