Code help

Hi: i´m writing my first code with arduino. In this project i need receive from a vb program in PC some data to configure one int variable. i´ll be using it after in a counter. this data is preceded with a char ('w') and i need separate this char from all the rest.Ex: 'w100'-> then i need separate the 'w' char from the int 100 because my variable setting must asume this value.
I couldn´t find any example in the libraries,forum or another site. Can anyone help me?
Thanks a lot

To get the value from the PC you probably want to use the serial interface, take a look at one of the example programs (most of the ones under Communications use serial) for how to use it. You will also need to set up your VB program to use the serial interface on your computer.

For the character manipulation you can compare the character received with what you are waiting for, i.e.:

const int MAX_SIZE = 5; //max number of digits in the number
char num[MAX_SIZE];
loop()
{
    if(Serial.available() && Serial.read() == 'w') //wait for a w
    {
        int i = 0;
        while(Serial.available())
        {
            num[i] = Serial.read();
            ++i;
        }
        variable = atoi(num);  //insert your variable here
    }
}

I think something like that should work, though you probably want some error checking etc.
I haven't done many of these programs myself so I'm not sure if the next serial character will have arrived by the time the while loop checks whether Serial.available() is true. If not then it's a little more complicated, but not very.
Hope this helps. :slight_smile:

Thanks a lot for your quick response, Zed0!
But the problem is like a bit more complex. Here is a piece of my actual code:
if (Serial.available()) {
val = Serial.read();
switch (val) {
case 'w1':
testeo=100;
break;
case 'w2':
testeo=200;
****************** and so on

i receive the message like 'w_nnn_' where nnn is an integer. Then after the message is received, i must separate the char 'w' from the number and allocate it in an int variable. Actually the nnn values are fixed like in the example, but this don´t works fine because i need use a lot of distinct values.
Anyway, again, thanks very much!

 switch (val) {
   case 'w1':

Is not valid 'C' - "w1" is a string (an array of char), not a character as implied by the single quote '.