sending More command (Val) to Arduino?


hello guys ,
my project controlling led light using visual basic program made me.

i have little problem in project , how can send more command arduino pc??

for example ,

this arduino codes uploaded ,

__________

int ledpin = 13; // number of led pin

void setup() {
serial.begin(9600); // set serial speed
pinmode(ledpin, output); // set led output
digitalwrite(ledpin, low); //turn off led
}


void loop(){
while (serial.available() == 0); // nothing if nothing sent
int val = serial.read() - '0'; // deduct ascii value of '0' find numeric value of sent number

if (val == 1) { // test command 1 turn on led
serial.println("led on");
digitalwrite(ledpin, high); // turn on led
}
else if (val == 0) // test command 0 turn off led
{
serial.println("led off");
digitalwrite(ledpin, low); // turn off led
}
else // if not 1 of above command, nothing
{
//val = val;
}
serial.println(val);
serial.flush(); // clear serial port
}


_____ 

as can see , ( val = 1 ) turn led 1 on , ( val = 2) turn led 1  off .
and added 2 more leds light same arduino sketch , ( val = 3 ) turn led 2  on , (val = 4 ) turn led 2 off , , same process other led ,

but when add 1 more led , , when type ( val = 10 ) the led 1 turn on ,


and don't know why led 1 turn on although specified val = 10 .


______

here how send (val) program made  in vb

private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click
        serialport1.open()
        serialport1.write("1")                                   <<<<< turn led 1 on
        serialport1.close()
    end sub

    private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click
        serialport1.open()
        serialport1.write("0")                                           <<<<<< turn led 1 off
        serialport1.close()

    end sub   

and same process other led depending on val



please 1 tell me how solve problems ,,

..you read 1 char..  '1'..  (read till eol)


Arduino Forum > Using Arduino > Programming Questions > sending More command (Val) to Arduino?


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support