econjack:
In your code, why do you need variable estado_? The if statement block really isn't needed:
void activar(int led, int estado){
digitalWrite(led, estado);
}
I'm assuming that the data coming in over the Serial object is a String like: "10110.", right? Also, adding a trailing underscore character to the name of a function argument is a bad way to name a temporary variable in the function.
Well, you're right, I don't know why I duplicated the variables, so it is fixed now, but the issue still persists.
Yep, the data is coming like you said and it works, but only in the Uno, in the Mega it doesn't do anything. And to add more salt to the wound, that was just a prototype, the full sketch involves controlling a RC car using bluetooth and the gamepad, it works, but I need to use the leds and I can't find a way to make that part work in the Mega, so I'm trying to make the prototype work before implementing the fix on the big sketch.
Thanks for your assistance.
Peter_n:
Can you tell what the data is that you send to the serial port ? What is the format ? So I can test it on my Mega.
This line is strange : String temp = (String) entrada.charAt(i);
I was expecting this : String temp = String( entrada.charAt(i));
http://arduino.cc/en/Reference/StringConstructor
You can read an integer from the Serial port with : Serial.parseInt() - Arduino Reference
A binary number can be read with : http://arduino.cc/en/Serial/read
Could you give the first parameter the name "pin" ? The name "led" confuses me : void activar(int pin, int estado){
I'm sending a string of inputs to the serial port, an int won't work because 001 might be converted into 1 and that would be incorrect.
Regarding the strange line, honestly I didn't find it strange because that's the way I use in java to cast values, so I went from a char to a string so I could then use the toInt() function to get the integer value of that char.
The first parameter of the function activar tells you the position in the led array to use, so let's say activar(1, 1) would mean that I would do a digitalWrite to leds[1] = 6 with a value of HIGH.
Thank you for your time.