
Automated safety gate logic
From Book 3: The Broken Bridge (Level 4: Code It, p. 28). Computers run the bridge gates with IF and THEN statements. IF a condition is true, THEN an action happens.
- IF river level is over 18 feet THEN close the safety gate and flash red lights
- ELSE IF wind speed is over 50 mph THEN show a high wind warning on the sign
- ELSE IF truck weight is over 40 tons THEN send the truck to the weigh station
- ELSE keep the gate open and show a green light
Scenario test: a storm pushes the river to 21 feet. What does the program do? A 2-ton family car arrives while the river sits at 10 feet. What color is the light? Then build your own: write one more rule you would add to keep the bridge safe.
