Thomas N wrote: > I have some trouble writing the control function to navigate the > robot around the house since there are many different combinations > of sensor state. Sure, I can write some "if/else statements" but > it looks like I will have 4096 (2^12) if/else statements! There > must be an efficient and easier way! Thomas: I'm not at all sure that the 4096 if/else statements would actually work; I suspect that you'd also want at least a one-step-back memory of your previous state, too. I'm also pretty sure that the binary tree that you describe wouldn't have to be completely populated... There are bound to be lots of short branches, so the total number of if/else statements would likely be less than 4096, anyway. Be that as it may, though, the usual method for solving this general sort of programming problem (mapping each combination of a set of input states to a particular set of output states) is to use a lookup table. In your case, you'd have a table with 4096 entries; each entry in the table would hold a description of the output that corresponded to that input. Using such a table, the pseudocode reduces down from 4096 if/else statements to: output = table[input] Good luck with your robot... -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu