I have the following code:
char switch_list[] = {
"PINB >> 7",
"PIND >> 1",
"PINB >> 1",
"PIND >> 0}"
};
void values(void){
uint8_t switch_value = 0;
if (i == 0){
switch_value = (PINB >> 7) & 1;
}
if (i == 1){
switch_value = (PIND >> 1) & 1;
}
if (i == 2){
switch_value = (PINB >> 1) & 1;
}
if (i == 3){
switch_value = (PIND >> 0) & 1;
}
SOME OTHER OPERATIONS GO HERE
}
I need to interpret the switch_list values as unsigned integers somehow, but I am not able to make any changes to the array (it needs to remain a char array). PINB and the others have defined 8 bit value in the libraries. I would like to create a for loop that looks something like this:
uint8_t switch_value = 0;
for (int i = 0, i < sizeof(switch_list)/sizeof(switch_list[0]); i++){
switch_value = **********[i] & 1;
SOME OTHER OPERATIONS GO HERE
}
}
Where ********* is the same as switch_list but instead of being of char type, it is uint8_t. Can anyone provide any tips?
PINBorPIND) and then perform a shift on it and return as auint8?PINxdefined?uint8_t f0() {return PINB >> 7;}or just make a support function if you don't like all the if statements inside the loop.