I am working on a maze navigation robot that moves through the maze using switches to make sure the robot keeps the wall of the maze on the right side of it at all times. Basically, all the switches are acting as is a push button that requires an action.
Here is my test code that lights an LED if the button is pushed
int temp;
while(1)
{
temp = (PINB & 0x01);
if(temp == 0)
{
PORT_ON(PORTB, 7);
}
else
{
PORT_OFF(PORTB, 7);
}
}
That's great if you want one switch, I'm planning on at least 3 or 4. The problems is this statement:
temp = (PINB & 0x01);
Is actually comparing the status of all B pins to my condition 0x01. As I add more switches, that logic comparison is going to get ugly unless I change my approach.
Is there any way I can check the status of an individual pin to see if it is on/off instead of the whole row? I'm using an atmega16 and modified $50 robot code.