Light Sensor Lab

Step 1.

For this lab we will need to see the Stage Layout.  Go to the Edit menu and make sure there is no checkmark beside Hide stage layout and you can see the Panda.

We need the stage because this is the only place we can see variables changing.

Step 2.

Go to the Events category and pull out when Flag clicked.

Step 3

Go to the Control category and pull our the forever loop.

Step 4.

Go to the Data&Blocks category.  Click on "Make a Variable".  Name it "light" and keep it For all sprites and click OK.

Step 5.

The options for the "light" variable will pop up.  Pull out "set light to 0" and put it inside the forever loop.

Step 6.

Go to the Robots category.  Scroll down and you will find the "light sensor -light sensor on board" script.

It is round like a variable-script, not like a puzzle piece!  Put it into the 0 of the "set light" script's box.

At this point, try running the program by pressing the Green flag.  You should see the continually changing value of the light variable on the stage (left side of screen).

Step 7.

Go to the Control category and pull out an if-then-else script.  Put it after the set-light script.

Step 8.

Go the Operators category and put a less than sign (<) into the if-then statement.

Step 9.

Go to the Data&Blocks category and put the "light" variable into the left side of the less-than sign.  Enter 100 into the right side.

This creates the action which will happen if the light is less than 100.

Step 10.

Go to the Robots category.  Pull out "set led led on board" into both the if-then and else statements.  Change the color on red of the first one to 60.

Note: we are picking 60 for the LED power because if it is too bright, it will interfere with the light sensor which is beside the RGB.

Short form of code:

This code has some unnecessary lines in it so that you can see the value of the light variable in the stage.

Removing this would shorten the code but you would not be able to see a screen output for the light variable: