Gweithgaredd

Dechreuwr | MakeCode, Python | Dangosydd LED, Synhwyrydd golau | Dewis, Rhif a gwerth lle, Synwyryddion

## Cam 1: Gwneud

### Beth yw e?

Has anyone been in your cookie tin? You can program your BBC micro:bit to act as an alarm to let you know! You will learn about selection, comparison logic, and the micro:bit's light sensor.

Mae'r ddau fideo hyn yn dangos i chi yr hyn y byddwch yn ei greu a sut i'w godio:

### Sut mae'n gweithio

• The program turns the micro:bit’s LED display into a light sensor.
• Put your micro:bit into the tin you wish to protect. When the lid is opened, the light sensor detects a change in light level and triggers the alarm.
• The program uses an infinite loop to keep sensing the light level.
• Selection ('if... else') and comparison logic (> 30) are used so that if the light level is above a certain amount, an angry face appears on the display; else, it clears the screen.

### Beth sydd ei angen arnoch

• micro:bit (neu efelychwr MakeCode)
• Golygydd MakeCode
• pecyn batri

## Cam 2: Codio

``````1from microbit import *
2
3while True: