Gweithgaredd

# Species counter

Dechreuwr | MakeCode, Python | Botymau, Dangosydd LED | Anifeiliaid, Ecosystemau, Newidynnau, Planhigion, Rhif a gwerth lle

## Cam 1: Gwneud

### Beth yw e?

Use your BBC micro:bit to help you count two different species of plants or animals in your school playground, garden or local park. You will learn about variables, and using the micro:bit's buttons and LED display.

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 variables called “A” and “B” to store the number of animals or plants counted.
• Variables store numbers or values that can change in a computer program.
• At the beginning of the program, “A” and “B” are set to zero and zero is shown on the LED display. You should always give variables an initial value in a computer program like this.
• Press button A each time you see a particular animal or plant, for example, a duck, and each time one will be added to “A”.
• Press button B each time you see another plant or animal of interest, for example, a goose, and each time one will be added to “B”.
• Shake your micro:bit to show the totals on the LED display.

### Beth sydd ei angen arnoch

• micro:bit (neu efelychwr MakeCode)
• Golygydd MakeCode
• battery pack (optional but recommended)

## Cam 2: Codio

``````1from microbit import *
2
3a = 0
4b = 0
5display.show(0)
6
7while True:
8    if button_a.is_pressed():
9        a += 1
10        display.scroll(a)
11    elif button_b.is_pressed():
12        b += 1
13        display.scroll(b)
14    if accelerometer.was_gesture('shake'):
15        display.scroll('A')
16        display.scroll(a)
17        sleep(1000)
18        display.clear()
19        sleep(2000)
20        display.scroll('B')
21        display.scroll(b)
``````

## Cam 3: Gwella

• Find a way of resetting the counter, for example, by pressing buttons A and B together.
• Make a graphical representation of the number of animals or plants counted, for example, by using dots.
• Show icons representing the animals or plants, or play sound effects, when you have reached a target number.