
Sensing
Forward Until Dark / Light • 10
©
Carnegie Mellon Robotics Academy / For use with LEGO
®
MINDSTORMS® Education NXT software and base set 9797
Forward until Dark Wait for Dark (cont.)
6. Download and Run the program.
6b. Download the program
Click Robot > Download Program.
6c. Run the program
Click “Start” on the onscreen
Program Debug window.
Tip: If your robot stops immediately
or runs past the line without
stopping, check your light sensor
values using the View mode.
Lighting conditions (position of
the sun, room lighting) may have
changed, and your threshold may
need to be adjusted.
Auto
Auto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
5a. Modify this code
Change the while() loop
condition’s value so that
it will check whether
the Light Sensor’s
value is greater than the
threshold value you
calculated in the last
lesson.
const tSensors lightSensor = (tSensors) S1;
//*!!CLICK to edit ‘wizard’ created sensor
task main()
{
while(SensorValue(lightSensor) > 40)
{
motor[motorC] = 50;
motor[motorB] = 50;
}
motor[motorC] = 0;
motor[motorB] = 0;
wait1Msec(2000);
}
5. Modify the (condition) in the while() loop to watch for the lightSensor value to be greater than
(brighter than) the threshold.
5b. Modify this code
Change the speed of
Motors C and B to 0
so that the robot stops
when it reaches a
black line, rather than
reversing at 50% power.
Komentarze do niniejszej Instrukcji