Let say your sensors are connected to bits 0 to 2 of a register called IR:
Code:
// Do something... (here I'll pass sensors data to the functions).
extern void not_in_weightbridge(unsigned int);
extern void go_ahead(unsigned int);
extern void go_back(unsigned int);
extern void right_place(unsigned int);
extern void not_possible(unsigned int);
// Get sensors data.
extern unsigned int getSensors( void );
extern int terminated; // flag to terminate main loop.
void main_loop( void )
{
unsigned int sensors;
// Table to functions sorted by the sensors data.
static const void (*actions[])(unsigned int) = {
not_in_weightbridge,
go_ahead,
right_place,
go_ahead,
go_back,
not_possible,
not_possible, /* 110 missing! */
not_possible
};
while ( ! terminated )
{
unsigned int sensors = getSensors() & 0x7;
actions[sensors](sensors);
}
}