i just tried it and seems to work
the names bitZero - bitSeven would be changed to match the register bits such as MUX1 , MUX2, obviously i would have to change it since it cant literally match
and the structure name would be changed to something like ADCsetup ..
now it would be ideal if i could initialize the fields to zero so i do not have to set each field to zero , but since this will be a generic reusable file for my self
ill have a function to initialize them all to zero
that way i only set the fields i am interested in
struct testReg
{
int bitZero ;
int bitOne ;
int bitTwo ;
int bitThree;
int bitFour;
int bitFive;
int bitSix;
int bitSeven;
};
struct testReg regEdit ; //structure that will represent a register and its settings
uint8_t myVar = 0;
void setup()
{
Serial.begin(9600);
DDRB |= 1<<PINB5 ;
}
int doTheMath()
// check each field of the structure and weather its true or false add that bit value to the uint8_t
{
regEdit.bitZero < 1 ? myVar = 0 : myVar = 1 ;
regEdit.bitOne < 1 ? myVar = myVar : myVar +=2 ;
regEdit.bitTwo < 1 ? myVar = myVar : myVar +=4 ;
regEdit.bitThree < 1 ? myVar = myVar : myVar +=8 ;
regEdit.bitFour < 1 ? myVar = myVar : myVar +=16 ;
regEdit.bitFive < 1 ? myVar = myVar : myVar +=32 ;
regEdit.bitSix < 1 ? myVar = myVar : myVar +=64 ;
regEdit.bitSeven < 1 ? myVar = myVar : myVar +=128 ;
return myVar;
}
void loop ()
{
regEdit.bitZero = false ;
regEdit.bitOne = false ;
regEdit.bitTwo =false ;
regEdit.bitThree = false;
regEdit.bitFour = false;
//ive set only the 5th bit to true , which i will pass to port B where bit 5 is the led on digital pin 13
regEdit.bitFive = true ;
regEdit.bitSix = false ;
regEdit.bitSeven = false;
PORTB ^= doTheMath();
Serial.println(doTheMath());
delay(50);
}