I think you may be asking about somthing i worked on recently
i wanted to get bit weighting so i could write a byte to the arduino and use it to switch individual outputs :-
(was based on an arduino Mega)
initiate the the required pins
int ledPin = 52;
int ledPin1 = 50;
int ledPin2 = 48;
int ledPin3 = 46;
int ledPin4 = 44;
int ledPin5 = 42;
int ledPin6 = 40;
int ledPin7 = 38;
in setup
set pins as outputs
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin2, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin3, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin4, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin5, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin6, OUTPUT); // initialize the LED pin as an output:
pinMode(ledPin7, OUTPUT); // initialize the LED pin as an output:
and this was in the loop
// only if there are bytes in the serial buffer execute the following code
if(Serial.available()) {
//keep reading and printing from serial untill there are bytes in the serial buffer
//while (Serial.available()>0){
if (Serial.available()>2){ // got 3 characters
// assume comes in as hundreds, tens, ones
hundreds = Serial.read() - 0x30; // read the byte & convert from ASCII to a number
tens = Serial.read() - 0x30;
ones = Serial.read() - 0x30;
// now make into a digit
incomingByte = hundreds*100 + tens*10 + ones;
}
Serial.print(incomingByte);
}
int value = (incomingByte);
digitalWrite(ledPin, (value >> 0 )% 2);// LSB
digitalWrite(ledPin1, (value >> 1)% 2);
digitalWrite(ledPin2, (value >> 2)% 2);
digitalWrite(ledPin3, (value >> 3)% 2);
digitalWrite(ledPin4, (value >> 4) % 2);
digitalWrite(ledPin5, (value >> 5) % 2);
digitalWrite(ledPin6, (value >> 6) % 2);
digitalWrite(ledPin7, (value >> 7) % 2); // MSB
I sent a value from 0-255 via the serial port which switched individual pin outputs.
the value was sent in the format 000 ~255 (alway 3 characters)
Hope this was helpful