wait block

16 views
Skip to first unread message

reneem...@gmail.com

unread,
Dec 31, 2013, 11:56:09 AM12/31/13
to cs4hsrobo...@googlegroups.com
Dear Prof. Kay,
When we program the robot to do the smile and the frown repeatedly, why is it that the wait block has to be outside the loop as opposed to next to the display blocks inside the switch block?  We do not understand the rationale?

Are we correct that when we do the high note low note repeatedly we never need the wait block because it is not a display?  Just wondering.  

Thank you

Jennifer Kay

unread,
Dec 31, 2013, 11:06:16 PM12/31/13
to cs4hsrobo...@googlegroups.com
Sorry, I'm not sure I understand the question. I'm going to assume this is "troubleshooting task 2" from Robot Project 4?

I'm not going to post code here, because I want you to try this out yourself, but I will post an outline of some code.

Note that in troubleshooting task 1, you are asked to NOT use a loop. That means you just play one note or the other. If you set the duration of your notes to 5 seconds, then you will stay in the switch for 5 seconds. So no matter what happens with your sensors, you're stuck in that switch for 5 seconds.

In troubleshooting task 2, you are asked to combine the loop and the switch.
  • If you were doing this with music, and you set the duration of your note to 5 seconds, then you'd still be stuck in the switch for 5 seconds before checking what's going on with your sensors
  • Similarly, if you do this with "display an image" followed by a wait for 5 seconds inside the switch, then you're stuck in the switch for 5 seconds before checking what's going on with your sensors.

  • On the other hand, if you changed the duration of your note to, say, 0.25 seconds, then you'd leave the switch relatively quickly, which would mean that you'd check what's going on with your sensors relatively quickly
  • Similarly, if you had a display block followed by a short wait of, say, 0.25 seconds, then you'd check what's going on with your sensors relatively quickly.
So, to answer your question. You can indeed put a (very short) wait block inside the switch rather than outside. The important thing is that your wait block has to be for a very short duration. Otherwise it will appear that the robot is not reacting to the ultrasonic sensor.
Reply all
Reply to author
Forward
0 new messages