Assign each bit ,in a serially received bitarray, into a function

hello, My aim is todo like the following, send some bits like "01001010" zero stands for off and 1 for on and every bit is responsible for an led. For example i send "00000000" now all leds are off else if "11111111" all leds are on, but the trick here is "0110101" so the first led is off the second and third in on then the 4th is off and the 5th is on.....etc... any ideas on how the code can be writen? those are just 8 bits, also does the arduino has any limitations if i did the same but with 80 bits?

-thanks

Why 8 bytes? Just send 1 byte with the eight 0 or 1 bits. Then just send 10 bytes total. Much faster.

See: http://www.rapidtables.com/code/text/ascii-table.htm

CrossRoads:
Why 8 bytes? Just send 1 byte with the eight 0 or 1 bits. Then just send 10 bytes total. Much faster.

oh i am very sorry i mixed the names , let me fix that.
so i would send 10 bytes every byte has 8 bits, so if i type a whole sequence which contains 80 bits like:“01…10” the arduino will translate those to 10 bytes rrite?

LarryD: See: http://www.rapidtables.com/code/text/ascii-table.htm

soo.....? do you mean that the arduino will convert every 8 bits to an ASCII Character?

The data is coming serially from another device? Then yes, just receive 10 bytes and do what you will with it - like shift into 10 shift registers that drive the LEDs.

You send the Arduino the ASCII character for your led on/off condition. Then in the Arduino you create a loop to read each bit in the character and respond accordingly. Numbers are in binary. .

CrossRoads: The data is coming serially from another device? Then yes, just receive 10 bytes and do what you will with it - like shift into 10 shift registers that drive the LEDs.

so do you have any ideas onto how to do that in code? let me tell you what i want to do, i have 10 arduinos every arduino has 8 leds and another master arduino that sends 80 bits of 0 and 1, so for example i want to turn on led 34 so the arduino searches until it reaches bit number 34 and sees if its 0 or 1.

LarryD: You send the Arduino the ASCII character for your led on/off condition. Then in the Arduino you create a loop to read each bit in the character and respond accordingly. Numbers are in binary. .

ok same idea but you say that instead of 80 bits we will just send 8 Characters"bits" which will be converted later into the arduino, you made it easier but how to tell the arduino that bit 5 in the decoded ASCII charachter"which is among other 8 chrachters which means that the arduino needs to know which ASCII bit to work on" is linked to led number 13 for example. Can u understand anything? XD

Why 10 arduinos? 10 shift registers would do.

digitalWrite (ssPin, LOW); // ssPin is D10
for (x=0; x<10; x=x+1){
SPI.transfer(ledArray[x]); // SCK D13 to SRCLK, MOSI D11 to serial data in, daisy chain serial data out
}
digitalWrite (ssPin, HIGH); // all outputs  update on this rising edge

CrossRoads:
Why 10 arduinos? 10 shift registers would do.

digitalWrite (ssPin, LOW); // ssPin is D10

for (x=0; x<10; x=x+1){
SPI.transfer(ledArray); // SCK D13 to SRCLK, MOSI D11 to serial data in, daisy chain serial data out
}
digitalWrite (ssPin, HIGH); // all outputs  update on this rising edge

bec the arduinos will be in different far places so there is no way to add shift registers

Not sure completely.

You have 10 Arduinos. Eight LEDs per Arduino.

Send two bytes. 1st byte identifies the Arduino. 2nd byte is the on/off condition

Example: send 5 then F this would mean Arduino #5 has a F (46 hex or 01000110 binary)

Will the master be connected to all of the slaves? Or will one slave receive the data and pass it along to the next slave?

CrossRoads: Will the master be connected to all of the slaves? Or will one slave receive the data and pass it along to the next slave?

every arduino will have an xbee installed ,so yeah every arduino is connected to the master

LarryD: Not sure completely.

You have 10 Arduinos. Eight LEDs per Arduino.

Send two bytes. 1st byte identifies the Arduino. 2nd byte is the on/off condition

Example: send 5 then F this would mean Arduino #5 has a F (46 hex or 01000110 binary)

thats not what i want but ok lets go with that, so the next step how to link every bit with an led after the arduino has received its ASCII and converted it?

See: https://www.arduino.cc/en/Tutorial/Array

Use similar technique to turn on LEDs on your particular Arduino.

.

will have to use bit shifting and a mask to determine if a bit is set or reset could also use bitRead(x,bitposition)

// in setup
pinMode (8, OUTPUT); // PORTB on Uno
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);

pinMode (11, OUTPUT);

pinMode (7, OUTPUT); // PORTD on Uno

pinMode (6, OUTPUT);

pinMode (5, OUTPUT);

pinMode (4, OUTPUT);



// in loop
PORTD = PORTD & 0x0F; // clear bits 7-6-5-4, leave 0-1-2-3 alone
PORTD = PORTD | (ledByte & 0xF0); // upper 4 bits to D7-6-5-4

PORTB = PORTB & 0xF0; clear bits 11-10-9-8, leave 12, 13 alone
PORTB = PORTB | (ledByte & 0x0F); / lower 4 bits to 11-10-9-8

Port Manipulation master.

CrossRoads: ``` // in setup pinMode (8, OUTPUT); // PORTB on Uno pinMode (9, OUTPUT); pinMode (10, OUTPUT);

pinMode (11, OUTPUT);

pinMode (7, OUTPUT); // PORTD on Uno

pinMode (6, OUTPUT);

pinMode (5, OUTPUT);

pinMode (4, OUTPUT);

// in loop PORTD = PORTD & 0x0F; // clear bits 7-6-5-4, leave 0-1-2-3 alone PORTD = PORTD | (ledByte & 0xF0); // upper 4 bits to D7-6-5-4

PORTB = PORTB & 0xF0; clear bits 11-10-9-8, leave 12, 13 alone PORTB = PORTB | (ledByte & 0x0F); / lower 4 bits to 11-10-9-8

ok great thats nearly what i want but like this: so PORTD = 0d01001010 but i want to replace "0d01001010" to the values recived from the serial, so it will be PORTD = values which will be identified at the beginning as "int values = Serial.Read()" am i going in the right path now?