Gweithgaredd

# Which way now?

Dechreuwr | MakeCode, Python | Dangosydd LED, Mesurydd cyflymiad | Ar hap, Dewis, Newidynnau, Offer perfformiad

## Cam 1: Gwneud

### Beth yw e?

Shake your micro:bit and be given a random direction to walk. You will learn about variables, and using random numbers, selection and comparison logic blocks.

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 uses a variable called “direction” to store a random number.
• Variables store numbers or values that can change in a computer program.
• Shake the micro:bit to set “direction” to a random number between one and three.
• The program then uses selection and comparison logic blocks to test the value of the variable.
• If “direction” is equal to 1, then an arrow pointing north shows on the micro:bit’s LED display. If “direction” is equal to 2, then the arrow points east. Otherwise, the arrow points west.
• To make the battery last longer, the program pauses for half a second after the arrow appears then clears the screen.

### Beth sydd ei angen arnoch

• micro:bit (neu efelychwr MakeCode)
• Golygydd MakeCode
• battery pack (optional but recommended)
• our set-up guide may be useful