I would like to configure my switch input type as either active high or active low. I wrote below code and I know it will not work because I when I multiply by 0, nothing works. One way is to write code to check ACTIVE LOW using if statement and handle. But I am sure there could be a simple method to perform logical NOT operation based on configurable bits. How to make the readSwitch() function configurable depending on switch input types?
#define ACTIVE_LOW 0
#define ACTIVE_HIGH 1
#define SWITCH_TYPE ACTIVE_LOW
uint8_t readSwitch(uint8_t pinNum)
{
uint8_t state=0;
if(SWITCH_TYPE*(PINC&(1<<pinNum)))
{
_delay_ms(20);
if(SWITCH_TYPE*(PINC&(1<<pinNum)))
{
state=1;
}
}
return(state);
}