Controlling Arduino with C#

Lets take the questions in reverse order.

how many ports can i use with the Duemilanove ATmega328P?

All of them. All one of them, to be specific. The Duemilanove has just one hardware serial port, connected to the USB port.

I can not operate arduino with the line : serialPort1.Write(LedIntensity.Value.ToString()); and receive the command/data at arduino with int LedIntensity_Scroll = Serial.read();

You are getting the numeric value from a field and converting it to a string, and sending that string to the serial port.

You are then trying to read the number that was sent. Where is the magic conversion of the string back to a number supposed to occur?

You are trying to read the 2nd byte of the string as a number only if the first byte is not a 1 (which it never is, since 1 is not a printable ASCII value, and you are only sending printable ASCII values).

    Serial.flush();

Throw away the rest of the string. Good idea. NOT.

First, you need to define a protocol. You want the sending application to be able to turn an LED on or off, using digitalWrite on the Arduino OR control the brightness of an LED using analogWrite. Currently, you are not telling the Arduino WHICH action it is to perform, just the data that it needs to perform the action, if it knew which action to perform.

You should be sending something like , , or , where < is a start of packet marker, D and A are commands, 0, 1, and 32 are values for the commands, and > is an end of packet marker.

All data is to be sent as strings.

Then, the Arduino needs to read the strings, store the data in an array, parse the array when the end of the packet arrives, and use the command and value to perform an action.

Search the forum for "started && ended" for an example of how to receive strings with start and end markers. There is a section in the code that I posted where you then perform the parsing and action.

Parsing is simple in your case. The command is a single letter. After determining the command, replace that letter with a 0, and call atoi with the rest of the string, to get an integer value. If the command is D, test the integer value for 0 or 1. If the command is A, analogWrite can be passed the value.