Download presentation
Presentation is loading. Please wait.
Published byAshley Owen Modified over 9 years ago
1
More switches Day 6 Computer Programming through Robotics CPST 410 Summer 2009
2
7/1/09Harry Howard, CPST 410, Tulane University2 Course organization Course home page Course home page (http://robolab.tulane.edu/CPST410/) Lab (Newcomb 442) will be open for practice with 3-4 Macs, but you can bring your own laptop and all robots.
3
Stop it Kelly §13
4
7/1/09Harry Howard, CPST 410, Tulane University4 The STOP block The STOP block, in the Complete palette under the Flow icon, stops a program from continuing. It is a good way to break out of loops. Tribot, beep until the Touch sensor is pressed.
5
7/1/09Harry Howard, CPST 410, Tulane University5 Stop.rbt
6
7/1/09Harry Howard, CPST 410, Tulane University6 The NXC analog NXC has a constant ‘break’ that breaks a loop whenever it is encountered in a program. How would you formulate the previous program for NXC? First you need an endless loop.
7
7/1/09Harry Howard, CPST 410, Tulane University7 The endless loop task main() { while (true) { // statements here }
8
7/1/09Harry Howard, CPST 410, Tulane University8 Stop.nxc first version task main() { while (true) { PlayTone(440,500); Wait(500); if (Sensor(S1) ????) { break; }
9
7/1/09Harry Howard, CPST 410, Tulane University9 Stop.nxc final version task main() { SetSensorMode(S1, SENSOR_MODE_PERCENT); while (true) { PlayTone(440,500); Wait(500); if (Sensor(S1) < 98) // unpressed = 100! { break; }
10
7/1/09Harry Howard, CPST 410, Tulane University10 Protect your robot Tribot, move forward until the Touch sensor is released.
11
7/1/09Harry Howard, CPST 410, Tulane University11 TouchStop.rbt
12
Pick a card, any card Kelly §12
13
7/1/09Harry Howard, CPST 410, Tulane University13 The RANDOM block In the Complete palette under the Data icon. It generates a number between 0 and 100, randomly.
14
7/1/09Harry Howard, CPST 410, Tulane University14 Display a random number Tribot, display a random number between 20 and 80 every time the left NXT button is pressed and then beep, until the right button is pressed.
15
7/1/09Harry Howard, CPST 410, Tulane University15 DisplayRandom.rbt
16
7/1/09Harry Howard, CPST 410, Tulane University16 Random numbers in NXC Random() Returns a single number chosen randomly between 0 and 2 16 or 65,536. Random(n) Returns a single number chosen randomly between 0 and n-1.
17
7/1/09Harry Howard, CPST 410, Tulane University17 Display a random number in NXC
18
7/1/09Harry Howard, CPST 410, Tulane University18 More than two choices SPOT, when I press the left NXT button, pick a number from 1 to 3. If the number is 1, display an image. If the number is 2, beep. If the number is 3, play a sound. Drag out a SWITCH block and turn off Flat view Control > Value Type > Number Conditions 1. > 1 2. > 2 + 3. > 3
19
7/1/09Harry Howard, CPST 410, Tulane University19 Switch3.rbt
20
7/1/09Harry Howard, CPST 410, Tulane University20 Next time P2 Multiple switches in NXC. Comparison: Kelly §15. The RANGE and LOGIC blocks: Kelly §16-17.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.