hello guys ,
my project is controlling LED light by using Visual basic Program made by me.
i have a little problem in my project , how can i send more command to the arduino from my PC??
for example ,
this is the Arduino codes that i uploaded ,
int ledPin = 13; // the number of the LED pin
void setup() {
Serial.begin(9600); // set serial speed
pinMode(ledPin, OUTPUT); // set LED as output
digitalWrite(ledPin, LOW); //turn off LED
}
void loop(){
while (Serial.available() == 0); // do nothing if nothing sent
int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number
if (val == 1) { // test for command 1 then turn on LED
Serial.println("LED on");
digitalWrite(ledPin, HIGH); // turn on LED
}
else if (val == 0) // test for command 0 then turn off LED
{
Serial.println("LED OFF");
digitalWrite(ledPin, LOW); // turn off LED
}
else // if not one of above command, do nothing
{
//val = val;
}
Serial.println(val);
Serial.flush(); // clear serial port
}
as you can see , ( val = 1 ) will turn LED 1 on , ( val = 2) will turn LED 1 off .
and i also added 2 more LEDs light to the same arduino sketch , so now ( val = 3 ) will turn LED 2 on , (val = 4 ) will turn LED 2 Off , and the same process to the other LED ,
but when i add one more LED , and when i type ( val = 10 ) the LED 1 Will turn On ,
and i don't know why LED 1 turn on although i specified the val = 10 .
here is how to send (Val) from my program i made in vb
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
SerialPort1.Open()
SerialPort1.Write("1") <<<<< this will turn LED 1 On
SerialPort1.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
SerialPort1.Open()
SerialPort1.Write("0") <<<<<< this will turn LED 1 off
SerialPort1.Close()
End Sub
and same process for the other LED depending on their Val
please could any one tell me how to solve this problems ,,