{"base":{"id":"cs9-17","subject":"Programming","title":"Programming a physical device","scene":"code9","steps":[{"mode":"light","eyebrow":"Sensor input","title":"Light level decides","body":"A small programmable board has a light sensor. The program reads it in a loop: when it's dark it shows a moon, otherwise a sun. Change the light level.","controls":[{"id":"light","label":"Light level","min":0,"max":100,"step":5,"value":30}]},{"mode":"buttons","eyebrow":"Button input","title":"Count the presses","body":"Button A adds 1 to a counter, B takes 1 away, and both together reset it. The count appears on the LED display. Press the buttons.","actions":[{"id":"a","label":"Press A"},{"id":"b","label":"Press B"},{"id":"ab","label":"Press A + B"}]},{"mode":"tempalarm","eyebrow":"Test it","title":"Vary the input, check the output","body":"A temperature alarm shows a cross and sounds above 30 °C. Test it: move the temperature through normal and extreme values and record the output in the table.","controls":[{"id":"temp","label":"Temperature","min":10,"max":40,"step":1,"value":22,"unit":"°C"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Inputs and outputs","body":"A device turns on a fan when its temperature sensor reads above 25 °C.","question":"Which is the input?","options":["The fan","The temperature reading","The display"],"answer":1,"right":"Correct. The sensor reading goes into the program; the fan is the output.","wrong":"Not quite. What does the program read?","look":"tempalarm"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"A device program runs once and stops.\"","body":"Most device programs loop forever, reading sensors again and again."},{"tag":"Popular idea","title":"\"Sensors make decisions.\"","body":"Sensors only measure; the program decides what to do."},{"tag":"Popular idea","title":"\"If it works at one temperature, it works at all.\"","body":"Test values either side of the threshold, and extremes."}]},{"type":"cards","id":"code","eyebrow":"Python-style code","title":"Device programs","items":[{"tag":"Light","title":"Night light","body":"while True:\n    if light_level() < 40:\n        show(MOON)\n    else:\n        show(SUN)","code":true},{"tag":"Buttons","title":"Counter","body":"count = 0\nwhile True:\n    if button_a.was_pressed():\n        count += 1\n    show(count)","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Smart home plan","items":[{"title":"Design a device","time":"20 minutes","need":["Paper"],"steps":["Choose a device: a plant-watering reminder, a door alarm or a night light.","List its inputs (sensors, buttons) and outputs (lights, sounds, motors).","Write its main loop in pseudocode.","Make a test table: input, expected output."],"why":"Real embedded systems are designed this way: inputs, decisions, outputs, then testing.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"Which is a sensor?","options":["A light sensor","An LED","A speaker"],"answer":0,"right":"Correct. It measures light.","wrong":"Not quite. Which one measures?"},{"question":"Which is an output device?","options":["A thermometer","A button","A buzzer"],"answer":2,"right":"Correct. It makes sound.","wrong":"Not quite. Which produces something?"},{"question":"Why do device programs often use 'while True'?","options":["To stop the device","To save memory","To keep checking the inputs"],"answer":2,"right":"Correct. It loops forever.","wrong":"Not quite. When should it stop reading?"},{"question":"Alarm above 30 °C. Which test value is most useful near the threshold?","options":["10 °C","31 °C","−5 °C"],"answer":1,"right":"Correct. Just above the threshold.","wrong":"Not quite. Test near the boundary."},{"question":"A step counter uses which sensor?","options":["Accelerometer (movement)","Light sensor","Microphone"],"answer":0,"right":"Correct. It detects movement.","wrong":"Not quite. What changes when you walk?"},{"question":"The program shows the wrong icon at 40 light. What should you check?","options":["The battery colour","The screen size","The condition (< or <=)"],"answer":2,"right":"Correct. Boundaries often hide bugs.","wrong":"Not quite. Look at the comparison."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["how a device program reads sensor or button input","how a decision chooses the output","why device programs loop","how to test a device with different inputs"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"sensor","meaning":"A device that measures something, such as light or temperature."},{"word":"input","meaning":"Data going into a program."},{"word":"output device","meaning":"Something controlled by a program, such as an LED or buzzer."},{"word":"embedded system","meaning":"A computer built into a device."},{"word":"threshold","meaning":"The value where a decision changes."}]},{"type":"sources","id":"sources","title":"Sources","items":["BBC Bitesize KS3 Computer Science","Raspberry Pi Foundation, Computing curriculum resources"]}]},"overlay":null}