<< Chapter < Page Chapter >> Page >

Introduction

Without Traffic lights, most of you wouldn’t be here today. Such simple little things, but if they break, chaos erupts. You’ve started to make a name for yourself as a hot-shot programmer and the Traffic Department wants to put some of your skills to use solving Cape Town’s traffic problems for the 2010 soccer world cup.

Programming tasks

Task 1 - flashing red when down

When the traffic lights fail, traffic must still flow. Have you ever seen traffic lights flashing red? If something goes wrong in the control system, real traffic lights try to tell all the cars that something is wrong and that the intersection now functions as a stop street. They do that by flashing the red light continuously. Try writing a program to flash the red light once.

Task 2 - flashing red three times

Flashing the red light once is good, but it’s not enough! Let’s flash the red light on and off three times.

Task 3 - flashing red continuously

Can you make it flash forever without taking forever to write the program?

Task 4 - normal sequence of lights

Ok, so the backup system works. Can you write the normal green, orange, red cycle?

Task 5 - pedestrian crossing

A little further down the road is a different traffic light, and this one is for pedestrians. Can you write a program to let a pedestrian cross when they press the button? The light should remain green. When a pedestrian presses the button it should turn orange and then red to allow the pedestrian to cross. After that it should turn back to green and be ready for the next pedestrian.

HINT: Use 'Wait for' block to wait for a button to be pressed

Task 6 - wait for more pedestrians

Pedestrians have been crossing the road in drips and drabs, slowing the traffic down unnecessarily. Can you write a program that only changes the light when three pedestrians have pressed the button?

HINT: Use the “Pulse Counter” The Pulse Counter works the same as the Wait button, except that it waits until it has been pressed the set amount of times before it allows the program to continue.

Task 7 - real-time feedback

This solution helps to reduce the traffic delays, but the pedestrians quickly notice that if they keep on pressing the button the light changes without having to wait for another pedestrian. Can you change the program so that the light is always green and only red whenever the button is pressed in?

HINT: Use the “Digital Branch” to make a decision

Task 8 - flashing a precise number of times

Remember how we were able to make the red light flash once, thrice or for ever. Can you make it flash very quickly for thirty times without switching the light on and off thirty times? What if we want to make it flash 1000 times? There must be an easier way than using the on and off command 1000 times? Write a program that shows a green light and when the button is pressed flashes the red light very quickly for thirty times before turning green again.

HINT: Use the “Counter Loop”.

Task 9 - sub programs

Task 1. Often we will find tasks that we need to repeat. For example we might want to flash the red light thirty times in different parts of our program. Instead of re-writing that part using the counter loop every time we need it, we can create our own block or sub-program to do that. Then our program from Task 8. will look much simpler. Then whenever and as often as we need to we can use this sub-program to flash the red light thirty times. We can put anything we want in a sub-program and it helps us to simplify our programs. Turn your counter loop from Task 8 into a sub-program.

Task 10 - combining the pieces

Now use all the tools you have learnt in the previous tasks and write a program which runs the regular traffic light sequence. When a pedestrian presses the button the lights need to switch to red and quickly flash thirty times to allow time for the pedestrian to cross before resuming the regular sequence.

Bonus tasks

The Traffic Department is well pleased with your efforts. Someone asks whether it is possible to adjust the brightness of the traffic lights - he believes it should only shine at 60% instead of 100% brightness. Can you do that?

Questions & Answers

Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Introduction to visual programming with robo pro. OpenStax CNX. Jan 27, 2011 Download for free at http://cnx.org/content/col11270/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to visual programming with robo pro' conversation and receive update notifications?

Ask