Questions
1) What kind of electrical connection is a whisker?
– The tactile switch; the single-pole, single-throw switch.
2) When a whisker is pressed, what voltage occurs at the I/O pin monitoring it? What binary value will occur in the input register? If I/O pin P8 is used to monitor the input pin, what value does IN8 have when a whisker is pressed, and what value does it have when a whisker is not pressed?
– When a whisker is pressed, the I/O line sees 0 (zero) voltage. The binary value will be 0 (zero). IN8 will have 0 (zero) voltage if a whisker is pressed and will have 1 voltage if a whisker is not pressed.
3) If IN7 = 1, what does that mean? What does it mean if IN7 = 0? How about IN5 = 1 and IN5 = 0?
– IN7 = 1 means the whisker is not pressed.
IN7 = 0 means the whisker is pressed.
IN5 = 1 means the whisker is not pressed.
IN5 = 0 means the whisker is pressed.
4) What command is used to jump to different subroutines depending on the value of a variable? What command is used to decide which subroutine to jump to? What are these decisions based on?
-The GOSUB is used to jump to different subroutines depending on the value of a variable. The IF…THEN command is used to decide which subroutine to jump to. That decision is based in conditions, which are logical statements that evaluate to true or false.
5) What is the purpose of having nested IF…THEN statements?
– They will be more fully introduced in the next activity.
Exercises
1) Write a DEBUG command for TestWhiskers.bs2 that updates each whisker state on a new line. Adjust the PAUSE command so that it is 250 instead of 50.
2) Using RoamingWithWhiskers.bs2 as a reference, write a Turn_Away subroutine that calls the Back_Up subroutine once and the Turn_Left subroutine twice. Write down the modifications you will have to make to the Main Routine section of RoamingWithWhiskers.bs2.
Projects
1) Modify RoamingWithWhiskers.bs2 so that the Boe-Bot makes a 4 kHz beep that lasts 100 ms before executing the evasive maneuver. Make it beep twice if both whisker contacts are detected during the same sample.
2) Modify RoamingWithWhiskers.bs2 so that Boe-Bot roams in a 1 yard (or meter) diameter circle. When you touch one whisker, it will cause the Boe-Bot to travel in a tighter circle (small diameter). When you touch the other whisker, it will cause the Boe-Bot to navigate in a wider diameter circle.