# Week 3 - Section 3 - Respond to light

 Site: ΕΛ/ΛΑΚ Moodle Course: Advanced Coding - June 2017 Book: Week 3 - Section 3 - Respond to light
 Printed by: Guest user Date: Friday, 13 September 2024, 9:46 PM

## Description

In the first week we will learn about the edison robot, its capabilities, sensors and communication with the software. We will also learn how to use the EdWare, the software for programming edison robots.

## Chapter 8.1 - Light alarm

Click the ‘Add Variable’ button in the top left corner and a pop up box will appear.

Type in the name of your variable as ‘Light_Level’, select the variable range as +/-32767 (word) and set the initial value to zero. Now click OK and your variable will be added to the variables table in the bottom right corner.

Now, write the following program to have the Edison robot sound an alarm when the lights in the room are turned on.

The sense light icon reads the light level from the left light sensor and places the reading into the variable called Light_Level.

The first loop uses mathematics to determine what to do.

Loop until the value in the variable called ‘Light_Level’ is ‘greater than’ (>) 100.

When the value in Light_Level is greater than 100 the loop is exited and goes to the next loop that sounds the alarm.

Place the Edison robot in the dark and press the play button. When the lights are turned on, the robot raises the alarm.

## Chapter 8.2 - Automatic lights

Write the following program to have the Edison robot turn the two LED lights on when it gets dark.

Drive the robot through a tunnel or under a couch and see the front lights come on.

In this program we are using the ‘less than’ (<) symbol to determine the path of the program. If the variable Light_Level is ‘less than’ 100, then take the true path and turn the LEDs on.

Experiment with the value (100) in the If icon.

## Chapter 8.3 - Follow the light

First, you have to create two word (16-bit) variables: Left_Light and Right_light

Write the following program to have the Edison robot follow light from a torch/flashlight.

Shine a torch/flashlight at Edison and the robot will drive towards the light.

This program performs a calculation between two variables. In the calculate word icon the variable Right_Light is subtracted from the variable Left_Light. The result (answer) is placed back into the variable Right_Light. Let’s see what the results would look like:

From the above you can see that when the torch is to the right the result is below zero (negative number). When the torch is to the left the result is above zero (positive number).

The If icon asks: Is the result less than zero? If true the robot drives left (towards the light), if false the robot drives right (towards the light).