Hello is there any easy way to get out a byte out of singel bits?
The bits should be read out of following digital inputs:
pinMode(Address0, INPUT); // Bit0
pinMode(Address1, INPUT); // Bit1
pinMode(Address2, INPUT); // Bit2
pinMode(Address3, INPUT); // Bit3
pinMode(Address4, INPUT); // Bit4
pinMode(Address5, INPUT); // Bit5
The byte should be assign to the byte variable "ADDRESS"
Is there any good way which mount the byte in this form and convert it to a decimal value :
ADDRESS (in Dezimal) = 0 , 0, Bit 5, Bit4, Bit3, Bit2, Bit1, Bit0
See http://arduino.cc/en/Reference/BitWrite
If you put the pin numbers in an array you can read each pin in turn and set/clear the corresponding bit in the byte using a for loop.
int pins[] = {3,4,5,6,7,8}; // you add the right pin numbers here, BIT5 first, BIT0 last
int myVal = 0;
for (int i = 0; i < 6; i++) {
myVal << 1;
myval |= digitalRead(pins[i]);
}
Serial.print (myVal);
If you use BitWrite() is more simple for a new user of C language:
ADDRESS =0; // all bits to 0
BitWrite(ADDRESS,0,digitalRead(Address0));
BitWrite(ADDRESS,1,digitalRead(Address1));
BitWrite(ADDRESS,2,digitalRead(Address2));
BitWrite(ADDRESS,3,digitalRead(Address3));
BitWrite(ADDRESS,4,digitalRead(Address4));
BitWrite(ADDRESS,5,digitalRead(Address5));
After this you have a value in ADDRESS. Now you can print to video the value as binary, decimal, hexdecimal or octal.
A value is a value. 255 decimal is FF hex or 11111111 binary