The Study Corner Light Indicator
Follow instruction sequences to guide the character to the goal.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- Scratch 3.0 online editor
🔧 Build Your Study Light Indicator
// MakeCode micro:bit Light Monitor
basic.forever(function () {
let light = input.lightLevel()
if (light < 60) {
basic.showIcon(IconNames.Asleep) // Dim light alert: turn on lamp!
} else if (light <= 160) {
basic.showIcon(IconNames.Happy) // Perfect ergonomic study light
} else {
basic.showIcon(IconNames.Skull) // Harsh glare warning!
}
basic.pause(500) // Sample twice per second
})
Multi-tier if-else branches categorize continuous light values into discrete health zones.
⚗️ Test your model
| Test Condition / Action | Expected Result |
|---|---|
| Cover sensor with palm (light < 60) | Displays Moon / Sleepy icon (turn on reading lamp) |
| Standard room lamp (60 <= light <= 160) | Displays Happy Face icon (safe, ergonomic studying) |
| Direct bright torch beam (light > 160) | Displays Glare warning icon (adjust lamp angle) |
Sound a soft auditory chime when the student has been reading in the dim light zone for over 3 minutes!
📖 Our Story & Concepts
Reading textbooks in poor evening light forces your pupils to dilate, causing severe eye strain, headaches, and reading fatigue. Conversely, studying under harsh direct bulbs creates reflective glare that irritates the retina.
The BBC micro:bit LED matrix doubles as a light sensor! By sensing photon energy striking the screen, it measures illumination from 0 (pitch dark) to 255 (blinding sun). Writing code that monitors thresholds transforms a small circuit into a practical health and ergonomics monitor.
</> Full Annotated Code Walkthrough
// Complete Light Monitor with Numeric Readout
let light = 0
input.onButtonPressed(Button.A, function () {
// Show exact numeric light level when Button A is pressed
basic.showNumber(input.lightLevel())
})
basic.forever(function () {
light = input.lightLevel()
if (light < 60) {
basic.showIcon(IconNames.Asleep)
} else if (light <= 160) {
basic.showIcon(IconNames.Happy)
} else {
basic.showIcon(IconNames.Target)
}
basic.pause(500)
})
Multi-tier if-else branches categorize continuous light values into discrete health zones.
▷ Expected Results & Troubleshooting
| Test Condition / Action | Expected Result |
|---|---|
| Cover sensor with palm (light < 60) | Displays Moon / Sleepy icon (turn on reading lamp) |
| Standard room lamp (60 <= light <= 160) | Displays Happy Face icon (safe, ergonomic studying) |
| Direct bright torch beam (light > 160) | Displays Glare warning icon (adjust lamp angle) |
⚑ Extension Challenges & Blueprints
- Level 1: Press Button A to scroll the exact numeric light reading across the screen.
- Level 2: Calibrate the threshold specifically for your own classroom by recording morning and evening light.
- Level 3: Connect an external LED on Pin 0 that automatically lights up when room light drops below 60.