Chapter 6: Light Sensitive Navigation with Photoresistors · Page 225
√ Instead of the value 6, try dividing the average variable by the values 3, 4, 5, 7,
and 9.
√ Run the program and test the Boe-Bot’s ability to exit a dark room with each
denominator value.
√ Decide what the optimum denominator value is.
Average_And_Difference:
average = timeRight + timeLeft / 2
difference = average / 6
RETURN
You can also change the denominator into a constant like this:
Denominator CON 6
Then, in your Average_And_Difference subroutine, you can replace 6 (or the optimum
value that you determined) with the
Denominator constant, like this:
Average_And_Difference:
average = timeRight + timeLeft / 2
difference = average / Denominator
RETURN
√ Make the changes just discussed, and verify that the program still works
correctly.
You can also use one less variable in this program. Notice that the only time the
average variable is used is to temporarily hold the average value, then it gets divided by
Denominator and stored in the difference variable. The difference variable is
needed later, but the
average variable is not. One way to fix this problem would be to
simply use the
difference variable in place of the average variable. It will work fine,
and you would no longer need the
average variable. Here is how the subroutine would
look:
Average_And_Difference:
difference = timeRight + timeLeft / 2