Understand the functions & characteristics of variables.
Learn to create & set variables
In this lesson, we’ll explore a robot named “Traffic Light”.
Traffic lights consist of three colors: red, yellow, and green (blue-green shade).
Green light: Vehicles are allowed to move.
Yellow flashing light:
Vehicles that have crossed the stop line can continue.
Vehicles approaching the stop line should slow down and stop.
Red light: Vehicles must stop and are not allowed to pass.
Traffic lights are important for:
Keeping urban traffic organized.
Reducing traffic accidents.
Ensuring safe travel for everyone.
The corpuscular theory states that light is made up of tiny particles called ‘corpuscles’ (little particles) that always travel in a straight line.
Light is a form of energy that travels from one place to another place at high velocity.
According to the Newton’s corpuscular theory:
Light is made up of tiny particles called ‘corpuscles’ having negligible mass.
These particles (corpuscles) are perfectly elastic.
The corpuscles are emitted from the luminous sources such as Sun, candle, electric lamp etc.
The tiny particles (corpuscles) always travel in a straight line in all directions.
Each particle (corpuscle) carries kinetic energy with it while moving.
The corpuscles travel at high velocity.
The corpuscles (light) would travel faster in the denser medium than in rarer medium. But later this is proved wrong. We know that light travels faster in the rarer medium than in denser medium.
When the particles (corpuscles) fall on the retina of the eye, they produce an image of the object or sensation of vision.
The corpuscles can be of different sizes. The different colors of light are due to the different sizes of the corpuscles.
The corpuscular theory explains the reflection of light in exactly the same way as the reflection of a perfectly elastic ball from a rigid plane.
When the corpuscles (particles) hit the reflecting surface, they are reflected from it in such a way that the angle of incidence is equal to the angle of reflection. This is due to the repulsion between the corpuscles and the reflecting surface.
According to Newton, when corpuscles (light particles) approach the refracting surface, they are attracted near the surface. When they enter the denser medium from a rarer medium, their speed increases and hence change their direction.
Wavelength of light is defined as “The distance between the two successive crests or troughs of the light wave”. It is denoted by the Greek letter lambda (λ).
Visible spectrum is nothing but the observable region of the electromagnetic wave which is visible to human eyes.
wavelength for various colours of the visible spectrum of light.
Red light has the longest wavelength in the visible spectrum (750 to 620 nm), making it highly visible from afar, especially in daylight.
Green has a medium wavelength (570 to 495 nm), making it visible without being harsh on the eyes.
Yellow falls between red and green in the spectrum (590 to 570 nm), creating a distinct warning signal
A variable originates from mathematics and is a fundamental concept in programming languages. It acts as a storage unit, much like a box in which you can place data. This box can hold various forms of data, such as numbers, text, or other types of information. The name of the box is the variable name, and the content inside the box is the variable value.
When a variable is first created, its value is often set to 0 or another default. Setting the variable value is like placing a specific piece of data into the box, and retrieving or modifying the value is as simple as accessing that box again.
This coding block should be the first block of your code.
This coding block will set the font size to default. It's also available in Medium, Large, Extra Large & Super Large.
It acts like an infinite while (true) loop & It's part of the Control category.
It keeps executing the code inside it until the program is explicitly stopped
The Repeat () block is a Control block.
Codings block held inside this block will loop a given amount of times, before allowing the script to continue.
Inside RoboCode, hover over the tab on the left.
Click on "Variables"
At the variables panel, Click "Make a Variable" to create a variable.
Named the variable accordingly.
Variable name cannot start with a number.
Variable name cannot have spaces and dash.
Variable name can have underscore in between words.
This block will set the specified variables to the given value.
This block will change the specified variable by a given amount.
Try this program in RoboCode 4.0
To create variables of X and Y, Go to "Variables" and Click "Make a Variable"
Program the traffic lights to follow a correct sequence:
Green → Yellow → Red, with specific timing for each light.
Green light stays on for 5 seconds.
Yellow light stays on for 2 seconds.
Red light stays on for 5 seconds.
Create a loop to repeat this sequence indefinitely.
Answer:
Program the traffic light for a pedestrians:
Imagine the initial condition of the Traffic Light is always "Green"
If pedestrians press the traffic light button (E6 Right Button), the Traffic light will change to "Yellow" for 3 seconds before turning to "Red" for safe crossing for at least (10 seconds) before turning back to "Green".
Answer:
The AI audio-visual module is a virtual electronic component that incorporates artificial intelligence algorithms, enabling machine recognition of external information. It features a high-definition camera at the front, capable of recognizing various types of images, including faces, gestures, pictures, tracks, spheres, colors, and more. Additionally, it is equipped with a voice collector below, which can capture and recognize speech.
ID No 1: Move Forward
ID No 2: Move Backwards
ID No 3: Turn Left
ID No 4: Turn Right
ID No 5: Stop
In order to use the AI Audio-Visual Module, Please install the "AI" extension.
From your current Traffic Light model, add the AI Audio-Visual module.
Try this code on RoboCode.
Work with a partner.
Program the traffic light based on the simulation below.
Pick a colored car to represents you.
Overview
Red Car (ID = 2) wants to turn right.
Blue Car (ID = 1) wants to move forward.
Green Car (ID = 4)wants to turn right.
White car (ID = 3) wants to turn left.
Conflict:
The Red Car turning right means it must yield to the Blue Car moving straight.
The Blue Car cannot go if the White Car is also moving left since that would cause a conflict.
Both the Red Car and Green Car turning right must also be considered in the traffic light system.
Traffic Light Logic:
If the Red Car (Player A) wants to turn right (ID = 4) and the Blue Car (Player B) wants to move forward (ID = 1):
The Blue Car's traffic light should be Green. When show the (ID = 1) at the White's car traffic light, it will appeared Red.
The White Car's (ID =3) traffic light should be Red. If the White Car want to turn left, Which traffic light should be Green & which would be Red?