pert:
Post a complete minimal sketch that demonstrates your best attempt. Explain exactly what you mean by "couldnt get it to work...and i was having trouble getting a string to char...".
Hi, sorry, forgot to post code...this is how I got it working at its simplest...send a value, analogWrite the value to a pin;
c# code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.Open();
}
private void trackBar1_MouseUp(object sender, MouseEventArgs e)
{
serialPort1.Write(trackBar1.Value.ToString());
}
}
Arduino code
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
}
void loop ()
{
while(Serial.available() > 0)
{
String val = Serial.readString();
analogWrite(11, val.toInt());
}
}
Robin2:
Have a look at the parse example in Serial Input Basics - it illustrates the use of strtok() and other things. The example assumes the separator is a comma, but you can change that easily if you want to.
As you are writing your own C# program my recommendation would be to send all the data in every message even if it has not changed - something like this <frontVal, rearVal, tvVal, hifiVal> so that the position of the number within the message defines its purpose. That will make your Arduino code much simpler than trying to distinguish "Front" and "Rear" etc.
If you do wish to send identifiers then it will be much simpler on the Arduino side if you just use single characters such as 'F' and 'R' - for example <F,255>
I am a great believer in using the PC program to do as much of the hard work as possible to make life easy for the Arduino.
...R
Thanks for the reply...I hadn't thought of making a message with all values in it. I will have a look at the post you've linked to...then begs the question, how will I tell the arduino what each value means, but I'm sure that will prob be answered in the link you gave me 
As it stands at the moment, this is what I have...
c# code
namespace Cabin_Lights
{
public partial class Form1 : Form
{
SerialPort myport = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports) PortSelect.Items.Add(port);
}
private void Connect_Click(object sender, EventArgs e)
{
if(PortSelect.Text != "")
{
myport.BaudRate = 9600;
myport.PortName = PortSelect.Text;
myport.Open();
if (myport.IsOpen)
{
Disconnect.Enabled = true;
Connect.Enabled = false;
}
}
else MessageBox.Show("Please Select A Port To Connect To", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void Disconnect_Click(object sender, EventArgs e)
{
if (myport.IsOpen)
{
myport.Close();
Disconnect.Enabled = false;
Connect.Enabled = true;
}
}
private void FrontBright_MouseUp(object sender, MouseEventArgs e)
{
myport.Write("FrontBright:" + FrontBright.Value);
}
}
}
Arduino code
String command;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
}
void loop()
{
if(Serial.available())
{
char incom = Serial.read();
if(incom == '\n')
{
parsecom(command);
command = "";
}
else command += incom;
}
}
void parsecom(String cmd)
{
String Part1, Part2;
Part1 = cmd.substring(0, cmd.indexOf(":"));
Part2 = cmd.substring(cmd.indexOf(":") + 1);
if(Part1.equalsIgnoreCase("frontbright"))
{
analogWrite(11, Part2.toInt());
}
}
EDIT
The arduino code is now updated...As it stands, using the arduino code above and the serial monitor window, it does exactly what I want it to do...but not with the c# program. I think this is due to the program writing a string, not a char. can i convert it or will I have to use the write command with the char[], offset and count args...in which case, I dont know how to use that...
Maybe something like this (tried but didn't work...slide and let go of the slider, but led stays off)
private void FrontBright_MouseUp(object sender, MouseEventArgs e)
{
byte[] buf = System.Text.Encoding.UTF8.GetBytes("FrontBright:" + FrontBright.Value);
myport.Write(buf, 0, buf.Length);
}
I think I forgot to mention that I want each section to (eventually) have brightness, fade & flash effects too, so was thinking of "FrontBright", "FrontFade", "FrontFlash" with a value after them.