-
map bits and pins
Hi,
I have unsigned char myvar, i got 5 bits and 5 pins 30, 40, 50, 60 and 70. need to map the bits to pins so that I loop though each bit in myvar and sets its pin High or low. I am using array but like to learn a clever way like using structs, unions, etc. :cool:
-
Don't. You want the exact opposite of a "clever way."
Try using a struct, instead:
Code:
struct {
int8_t bp_pin_id;
uint8_t bp_bit_mask;
int8_t bp_set_state;
} Bits_to_pins = {
{ 30, 0x40, PIN_HIGH },
{ 40, 0x01, PIN_LOW },
{ 50, 0x02, PIN_LOW },
{ 60, 0x80, PIN_HIGH },
{ 70, 0x08, PIN_LOW },j
};