byte is an 8-bit integer. 11111110 (decimal) is 110110010000001112 (binary). The top bunch will be cut off because it doesn't fit in 8 bits, so your number is now just 1112 or 710. If you wanted led to be 111111 in binary, you can use hex notation: byte led = 0x3f;
Aside from that, your code looks pretty much correct, although could be a lot shorter and easier to understand if you used an array for the pin numbers.
Your setting a byte to 111 where you should be using 0b111 for binary. Also, bit numbers start from 0 not 1 so you never read the least significant bit. The result returned is the state of the requested bit so it will return 1 or 0 depending if the bit was set (1) or clear (0).
Your only supplying a code snippet but from what I can see you could vastly simplify your code by using an array to store LED pin numbers. You could also use if..else as the bit states are either on or off
I did put 111 to test I will be receiving data that looks like this 101010 using led = Serial.read();
Will I be able to converte it as binary like you said?
Should I still declare led as Byte?
I could use and array list, i will do so as soon as it works.
With 0x3f i get all the Leds on except for the LightLeft1.
Best regards
I will be receiving data that looks like this 101010 using led = Serial.read();
What is sending that data? You REALLY need to be clear on what you are expecting. If the data is being sent by a computer, as binary data, the computer will be sending 0x101010. If you are typing the string "101010" into the serial monitor, the you will be reading ONE of those characters per call to Serial.read(), so bitRead() doesn't come into play at all.
At maximum I will have 6 leds on so 111111.
Yes you are right ' ' are for char, i'm not sure I can send string, and i don't think it will be a good idea anyways as it is harder to handle with arduino for what i want to do.
ok thank you,
how come there is a difference between if i use led=serial.read() and if for my tests i write led=111111, this is what blocks me from understanding I guess.
how come there is a difference between if i use led=serial.read() and if for my tests i write led=111111, this is what blocks me from understanding I guess.
Because 111111 is an integer value. What is sent over the serial port is a string of characters. There is a big difference between reading a string of characters, one at a time, and having an int.
I'm my Processing console i'm getting the wanted output: temp: 00001100.
Meaning i want my 5th and 6th LED on.
On the arduino side
This is where i'm having issues, at the moment i'm using an ArduinoMega 32 board with the version 0022 of the arduino develloping tool. I should be receiving my duemilanove tomorrow.
I can't seem to be able to use String: ( "String does not name a type").
You test that there is one byte of data, or more, available to read. Then, you read that character. If it's a '>', you drop into this loop. There may be nothing to read, but you read and store that nothing as fast as you can.
In addition to that being wrong, you are looking at one character. It's not a >, so you read and store the next (possibly non-existent) value.
You need to read and store the character:
int c;
while((c = Serial.read()) != '>')
{
Then, you need to make sure that c is not -1 before you store it.
if(c != -1 && count < ??) // Whatever your array size is (minus 1, of course)
{
tab[count++]=c;
tab[count] = '\0'; // In addition you MUST NULL terminate the array
}