Rydym wedi addasu'r deunydd a gafodd ei greu ar gyfer ein Clwb Roboteg fel bod pawb yn gallu ei ddefnyddio gartref neu yn yr ysgol.
Mae pob un o'r sesiynau isod yn cynnwys gwers fideo gan aelod o'n staff a set o ymarferion i asesu eich dealltwriaeth. Gan fod y dudalen hon ar gyfer dysgwyr annibynnol, mae'r atebion wedi'u cynnwys.
Dewiswch bennawd sesiwn i gychwyn.
Gwers Fideo (yn Saesneg):
Ymarferion:
Rydym wedi creu her ar dair lefel (efydd, arian ac aur) er mwyn i ddysgwyr ddechrau ymchwilio a chreu rhaglenni yn Microsoft Makecode.
Dylai pob dysgwr ymgymryd â'r her efydd i gychwyn cyn rhoi cynnig ar yr heriau uwch.
Cliciwch ar bennawd pob her i gael y manylion.
Creu rhaglen (yn Makecode) sy'n gwneud y canlynol:
Pan fydd y rhaglen yn dechrau, rhaid sicrhau bod y LEDs yn dangos delwedd o'ch dewis.
Gair o gyngor: I ddileu blociau, pwyswch y botwm dileu ar eich bysellfwrdd neu llusgwch y blociau yn ôl i'r ddewislen.
Gallwch ddefnyddio delwedd sy'n bodoli eisoes gyda'r bloc 'dangos eicon' neu greu eich delwedd eich hun gan ddefnyddio'r bloc 'dangos leds'.
Os ydych chi'n defnyddio'r bloc 'dangos leds', gallwch glicio ar y sgwariau i ddewis a ydyn nhw'n cael eu goleuo ai peidio.
Byddwch ond eisiau gweld y nodwedd hon pan fydd y rhaglen yn dechrau, felly dylech ei rhoi yn y bloc 'ar ddechrau'.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Defnyddiwch y bloc 'dangos leds':
ar ddechrau
dangos leds
Defnyddiwch y bloc 'dangos eicon':
ar ddechrau
dangos eicon
⯆
Ar ôl cwblhau'r cam cychwyn, dylech ddefnyddio'ch rhaglen i chwarae animeiddiad drosodd a throsodd nes eich bod yn stopio'r rhaglen.
Gair o gyngor: Cyfres o ddelweddau yw animeiddiad sy'n gwneud i wrthrych edrych fel petai'n symud.
Bydd angen i chi ddefnyddio'r bloc 'am byth' i wneud hyn.
Gellid defnyddio dwy ddelwedd yn unig i greu animeiddiad syml.
Er enghraifft, gallwch ddefnyddio'r bloc 'dangos eicon' ar gyfer y galon fawr ac yna'r galon fach. Bydd hyn yn creu animeiddiad sy'n edrych fel calon yn curo.
Does dim angen saib ar gyfer cyfres o ddelweddau sy'n gwneud animeiddiad oni bai eich bod am arafu'r lluniau.
Gallwch ddefnyddio 'dangos leds', 'dangos eicon', neu gyfuniad o'r ddau.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
am byth
dangos leds
dangos leds
dangos leds
Mae hyn yn dangos nad oes angen i chi ddefnyddio llawer o LEDs i greu animeiddiad.
Gofalwch fod delwedd wahanol yn ymddangos ar eich Micro:Bit wrth bwyso botwm A.
Gair o gyngor: Mae botwm A yn fewnbwn, felly chwiliwch am y ddewislen sydd â'r bloc sydd ei angen arnoch.
Gair o gyngor: I brofi'r rhaglen, dydy'r botwm A ddim yn cyfateb i'r botwm A ar eich bysellfwrdd. Mae'n cyfeirio at y botwm A ar Micro:Bit y tu mewn i'r efelychydd, a gallwch glicio arno gyda'ch llygoden.
Mae'r bloc y bydd ei angen arnoch ar gael yn y ddewislen bloc Mewnbwn.
Dydy'r bloc hwn ddim yn mynd y tu mewn i'r blociau 'ar ddechrau' neu 'am byth'. Yn hytrach, mae'n dechrau adran newydd o flociau cod.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar fotwn A ⯆ wedi'i wasgu
dangos eicon
⯆
Ychwanegwch sain neu gerddoriaeth at eich dilyniant cychwyn.
Gair o gyngor: Dylech sicrhau bod lefel sŵn eich cyfrifiadur yn isel cyn ychwanegu sain. Gallwch addasu'r sŵn yn ystod y prawf i lefel o'ch dewis.
Gair o gyngor: Os ydych chi'n defnyddio cerddoriaeth, dylech gadw'r alaw yn fyr a'i chwarae unwaith yn unig, neu bydd rhaid i chi aros am amser hir nes bod yr alaw wedi gorffen yn ystod pob prawf.
Gair o gyngor: Os nad ydych am greu eich alaw eich hun, sgroliwch i lawr y ddewislen Cerddoriaeth i ddod o hyd i alawon a synau parod.
Os ydych chi'n defnyddio'r bloc 'play melody' ar frig y ddewislen Cerddoriaeth, gallwch greu eich alaw eich hun trwy glicio ar y symbol nodyn cerddorol yn y bloc, yna uwcholeuo'r bocsys i greu nodau gwahanol.
Os ydych chi'n defnyddio'r bloc 'play melody' gydag alawon sydd wedi'u rhagosod, dylech newid yr opsiwn 'in background' i 'until done' gan ddefnyddio'r saeth i lawr.
Os ydych yn dal i gael trafferth, defnyddiwch y botwm ateb isod.
Defnyddio eich alaw eich hun:
ar ddechrau
dangos leds
play melody ♫ at tempo 120 (bpm)until done ⯆
Defnyddio alaw sydd wedi'i rhagosod:
ar ddechrau
dangos leds
play melody ffync ⯆until done ⯆
Defnyddio effaith sain:
ar ddechrau
dangos leds
play hapus ⯆until done ⯆
Gofalwch fod y Micro:Bit yn ymateb pan fydd yn clywed sain uchel.
Gair o gyngor: Dangosodd y fideo fod y meicroffon yn gweithredu fel synhwyrydd sain a'i fod yn ddyfais fewnbynnu.
Gair o gyngor: Gallech ddefnyddio delwedd, testun, cerddoriaeth neu sain fel ymateb.
Gair o gyngor: Sain uchel yn y rhaglen hon yw unrhyw beth dros 170.
Mae'r bloc sydd ei angen arnoch ar gael yn y ddewislen blociau Mewnbwn.
Edrychwch o dan micro:bit (V2). Mae'r bloc yn yr adran hon oherwydd bod dau fersiwn o BBC Micro:Bit ar gael erbyn hyn a dim ond fersiwn 2 sydd â meicroffon.
Bydd angen i chi wylio'r fideo eto os ydych chi'n ansicr sut i greu sain uchel yn yr efelychydd.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Mae'r datrysiad hwn yn sicrhau bod y Micro:Bit yn dangos neges pan fydd yn clywed sain uchel.
ar sain uchel ⯆
dangos testun " SHHH! "
Defnyddiwch yr un rhaglen i greu'r canlynol:
Ar ddiwedd eich dilyniant cychwyn, cliriwch y sgrin ac ychwanegwch neges groeso.
Gair o gyngor: Defnyddiwch neges fer oherwydd bydd angen i chi aros iddi gwblhau bob tro y byddwch yn profi'ch rhaglen.
Gair o gyngor: Mae'r ddau floc sydd eu hangen i wneud hyn ar gael yn y ddewislen Sylfaenol.
Ym maes rhaglennu, rydym yn defnyddio'r gair testun i ddisgrifio unrhyw gyfres o symbolau.
Bydd angen i chi ddod o hyd i'r bloc 'dangos testun' cyn gallu newid y gair "helo" i air/neges o'ch dewis.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar ddechrau
dangos leds
clirio sgrin
dangos testun " Hi "
Ychwanegwch neges i'ch dolen 'am byth' sy'n dweud 'Angen Mewnbwn'.
Gair o gyngor: Dylech drin y sgrin hon fel sgrin aros.
Byddwch yn defnyddio'r un bloc ag a ddefnyddiwyd gennym ar gyfer y neges groeso uchod.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
am byth
dangos leds
dangos leds
dangos leds
dansos testun " Angen Mewnbwn "
Sicrhewch fod y Micro:Bit yn arddangos delweddau gwahanol pan fydd y botwm B yn cael ei bwyso a phan fydd y ddau fotwm yn cael eu pwyso.
Gair o gyngor: Mae gan y bloc 'ar fotwm A wedi'i wasgu' saeth i lawr sy'n eich galluogi i newid yr A i B neu A+B.
Cofiwch fod modd dod o hyd i'r blociau botwm yn y ddewislen Mewnbwn.
Bydd angen tri o'r blociau hyn arnoch yn eich rhaglen, un ar gyfer pob cyfuniad o fotymau.
I brofi hyn, dylai'r efelychydd fod â botwm newydd sydd wedi'i labelu A+B, sy'n gadael i chi ddynwared effaith pwyso'r ddau fotwm gan ddefnyddio'r llygoden.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar fotwm B ⯆ wedi'i wasgu
dangos eicon
⯆
ar fotwm A+B ⯆ wedi'i wasgu
dangos eicon
⯆
Ychwanegwch effeithiau sain gwahanol gan ddibynnu ar ba fotwm sy'n cael ei bwyso.
Gair o gyngor: Mae'n bosibl y byddwch yn dechrau gweld rhai mathau o ymddygiad digroeso yn eich profion wrth i ni ychwanegu mwy o flociau at y rhaglenni botwm. Byddwn yn rhoi sylw i pam mae hyn yn digwydd a sut i osgoi hyn yn nes ymlaen yn y gyfres.
Os nad ydych chi'n ansicr, gweler cam 4 yn yr her efydd.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar fotwn A ⯆ wedi'i wasgu
dangos eicon
⯆
play piffian chwerthin ⯆until done ⯆
ar fotwm B ⯆ wedi'i wasgu
dangos eicon
⯆
play dirgel ⯆until done ⯆
ar fotwm A+B ⯆ wedi'i wasgu
dangos eicon
⯆
play cynyddol ⯆until done ⯆
Ychwanegwch adwaith ar gyfer pan fydd y Micro:Bit yn canfod ei bod yn dawel.
Gair o gyngor: Mae llawer o flociau yn cynnwys cwymplenni sy'n eich galluogi i newid geiriau allweddol.
Gair o gyngor: Ar gyfer y Micro:Bit, ystyr tawel yw unrhyw lefel sŵn o dan 90.
Cofiwch fod canfod sain yn fewnbwn.
Mae modd newid y bloc 'ar sain uchel'.
Gallai adwaith fod yn sain, yn ddelwedd, yn eicon neu'n neges.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar sain tawel ⯆ sound
dangos leds
Parhau i greu eich rhaglen trwy ychwanegu'r canlynol:
Newid y ddelwedd sy'n ymddangos wrth gychwyn gydag animeiddiad.
Gair o gyngor: Gallech ddefnyddio delweddau ailadroddus, neu efallai y byddwch am ddefnyddio bloc o'r ddewislen Dolennau i helpu gyda hyn.
Mae yna floc 'ailadrodd 4 o weithiau' yn y ddewislen Dolennau a gellir ei osod i ailadrodd faint fynnwch chi o weithiau. Mae hyn yn golygu mai dim ond unwaith y bydd angen i chi ddefnyddio pob delwedd.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Mae animeiddiad cychwyn y rhaglen hon yn dangos calon yn curo.
Newidiwch eich animeiddiad dolen am byth i ddangos person neu anifail yn symud i'r sgrin.
Gair o gyngor: Ewch ati i ddewis neu greu delwedd lawn o'ch person/anifail yn gyntaf. Yna bydd hi'n haws i chi greu'r animeiddiad.
Gofalwch fod eich anifail/person yn ymddangos o ochr chwith eich sgrin gan ddefnyddio un golofn o oleuadau ar y tro cyn ei symud yr holl ffordd ar draws y sgrin.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
am byth
dangos leds
dangos leds
dangos leds
dansos testun " Angen Mewnbwn "
Newidiwch adwaith y Micro:Bit drwy ogwyddo i'r chwith a gogwyddo i'r dde.
Gair o gyngor: Mae gan rai blociau gwymplenni i newid gair allweddol.
Gair o gyngor: Mae'r Micro:Bit yn defnyddio ei fesurydd cyflymu ar gyfer hyn, sy'n synhwyrydd symudiadau. Ai allbwn neu fewnbwn yw hwn?
Bydd angen i chi ddefnyddio bloc o'r ddewislen Mewnbwn.
Oes bloc sy'n seiliedig ar symud y gallwch chi ei ddefnyddio? Pa opsiynau sydd ganddo ar gyfer y gair allweddol?
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar gwyro i'r chwith ⯆
dangos leds
ar gwyro i'r dde ⯆
dangos leds
Ychwanegwch effeithiau sain at y gogwydd i'r chwith a'r dde.
Mae'r un broses ar waith â phan wnaethom ni ychwanegu effeithiau sain at fewnbynnau'r botwm.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
ar gwyro i'r chwith ⯆
dangos leds
play sleid ⯆until done ⯆
ar gwyro i'r dde ⯆
dangos leds
play disgleirio ⯆until done ⯆
Ar ddiwedd eich dolen am byth, ewch ati i ddisodli'r bloc 'dangos testun Need Input' â bloc sgrin glir ac yna dangoswch lefel y sain yn lle hynny.
Gair o gyngor: Mae lefel y sain ar Micro:Bit yn cael ei mesur ar ffurf rhif.
Gair o gyngor: Bydd angen i chi uno dau floc gyda'i gilydd i greu'r cyfarwyddyd hwn.
Mae'r ddewislen Sylfaenol yn cynnwys bloc 'dangos rhif'.
Mae'r synhwyrydd sain yn ddyfais fewnbynnu, felly bydd angen i chi edrych yn y ddewislen Mewnbwn ar gyfer y bloc a fydd yn mynd i mewn i'ch bloc 'dangos rhif'.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
am byth
dangos leds
dangos leds
dangos leds
clirio sgrin
dangos rhif lefel sain
Gwers Fideo (yn Saesneg):
Ymarferion:
Ar gyfer y sesiwn hon byddwn yn creu rhaglen i droi eich BBC Micro:Bit yn anifail anwes rhithwir.
Fel sy'n wir am bob un o'n hymarferion, mae dysgwyr yn cwblhau un lefel cyn symud i'r nesaf. Fel arall, mae'n bosibl y bydd dysgwyr yn methu derbyn gwybodaeth neu'n gadael allan cam hanfodol sy'n atal y rhaglen rhag gweithio.
Cliciwch ar bennawd pob her i gael y manylion.
Dechreuwch raglen Micro:Bit newydd ar Makecode gan gwblhau'r camau canlynol.
Ewch ati i greu neges a/neu ddelwedd sy'n ymddangos ar ôl pwyso dechrau er mwyn helpu i nodi'r rhaglen.
Gair o gyngor: Cofiwch fod modd defnyddio'r bloc clirio'r sgrin i greu toriad rhwng delwedd a neges.
Ewch ati i greu animeiddiad bach o'ch anifail anwes yn aros y tu mewn i'r ddolen am byth.
Gair o gyngor: Efallai y gallwch ddefnyddio animeiddiad y gwnaethoch chi ei greu yn Sesiwn Un.
Cofiwch, dim ond dwy ddelwedd sydd eu hangen arnoch i wneud animeiddiad.
Gallwch ddefnyddio'r eiconau sydd wedi'u creu ymlaen llaw i'ch rhoi ar ben ffordd.
Po fwyaf o ddelweddau rydych chi'n eu defnyddio, y mwyaf o amser y bydd ei angen i gwblhau'r ddolen am byth - gallai hyn achosi problemau wrth i ni greu'r rhaglen.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Defnyddiwch un o'r mewnbynnau (fel botwm A) i fwydo'ch anifail anwes ac ewch ati i'w ddefnyddio i ddangos delwedd o eitem fwyd ar y sgrin.
Efallai y bydd angen i chi glirio'r sgrin cyn dangos eich delwedd bwyd.
Cofiwch fod bloc rheoli botwm A wedi'i leoli yn y ddewislen Mewnbwn.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Mae'r ateb hwn yn cynnwys fy ymgais i dynnu llun o fyrgyr ar gyfer fy anifail anwes.
Ewch ati i greu animeiddiad sy'n dangos yr anifail anwes yn bwyta.
Pwysig: Mae'n bosibl y byddwch yn dechrau gweld rhai mathau o ymddygiad digroeso wrth i'ch animeiddiadau wrthdaro. Trwy ddefnyddio ein blociau os-datganiad newydd, gallwn gywiro'r broblem a storio'r rhaglen gyfan y tu mewn i un ddolen am byth. Mae'r ddelwedd isod yn dangos sut i gynnwys botwm A fel amod mewn os-datganiad y tu mewn i'r ddolen am byth.
Nodwch: Hira'n byd fydd eich dolen am byth, mwya'n byd y bydd hi'n ei gymryd i'r rhaglen ymateb i fewnbwn. Mae'n bosibl y bydd angen i chi ddal y mewnbynnau am fwy o amser er mwyn eu cofnodi.
Cofiwch: Dim ond un ddolen am byth y dylech ei chael yn eich rhaglen.
Gair o gyngor: Defnyddiwch yr adran arall yn y bloc os-datganiad hwn fel cartref newydd i'ch anifail anwes sy'n aros am animeiddiad.
Gallwch animeiddio'r anifail anwes neu'r bwyd ar gyfer yr effaith hon.
Bydd bloc ailadrodd o'r ddewislen Dolennau yn helpu gyda'r animeiddiad.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Ewch ati i greu ymateb gwael gan eich anifail anwes (gallwch ddefnyddio delwedd, animeiddio, a/neu sain) pan fydd yn clywed sŵn uchel.
Gair o gyngor: Yn hytrach na defnyddio'r bloc 'ar sain uchel', defnyddiwch os-datganiad arall y tu mewn i'ch dolen am byth ar gyfer lefel sain > 175.
Gallwch ehangu os-datganiad trwy glicio ar yr arwydd plws. Gallwch wneud hyn ar gyfer cynifer o os-datganiadau eraill ag y dymunwch.
Gallwch ddod o hyd i'r bloc mwy na yn y ddewislen Rhesymeg.
Er mwyn profi eich rhaglen, defnyddiwch y bar newydd ar gyfer lefel sain y meicroffon yn eich Micro:Bit wedi'i efelychu er mwyn newid y lefel. Pan fyddwch yn mynd dros 175 dylech weld y rhaglen - efallai y bydd ychydig o oedi.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Gan barhau â'r un rhaglen, ewch ati i gynnwys yr ychwanegiadau isod.
Defnyddiwch y rhaglen i drefnu bod eich anifail anwes yn mynd i gysgu pan fydd hi'n tywyllu (defnyddiwch lai na 70 neu'n hafal i 70 ar gyfer y gwerth hwn).
Gair o gyngor: Gallwch gael cynifer o os-datganiadau ag y dymunwch mewn rhaglen Micro:Bit.
Defnyddiwch y botwm plws ar waelod eich os-datganiad i ychwanegu arall os-datganiad at eich rhaglen.
Gwiriwch pa symbol rydych chi'n ei ddefnyddio ar gyfer y gymhariaeth. Dylai edrych fel hyn ≤.
Gallech ddefnyddio testun o 'zzz' i ddangos bod eich anifail anwes wedi mynd i gysgu.
Cofiwch glirio'r sgrin yn gyntaf.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Ewch ati i greu newidyn ar gyfer 'llawnder' sy'n cynyddu fesul un bob tro y caiff eich anifail anwes ei fwydo.
Gair o gyngor: Mae gosod newidyn newydd i sero wrth ddechrau yn arfer da bob tro.
Mae yna newidyn newid fesul bloc sy'n gwneud yr hyn sydd ei angen arnom.
Pa ran o'r cod y mae angen iddo fynd i mewn iddi?
Dylech sicrhau nad ydych chi'n ei osod y tu mewn i ddolen ailadrodd animeiddiad.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Defnyddiwch fewnbwn (botwm B efallai) a fydd yn dangos gwerth 'llawnder' i'r defnyddiwr.
Gallwch roi newidyn y tu mewn i floc 'dangos testun'
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Defnyddiwch y rhaglen i wneud i'ch anifail anwes ymateb yn hapus i olau llachar (defnyddiwch fwy na 200 ar gyfer y gwerth hwn).
Os ydych chi wedi dewis gwneud animeiddiad, cofiwch am y bloc ailadrodd yn y ddewislen Dolennau.
Cofiwch sicrhau mai > yw eich symbol cymharu.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Fe wnes i ddewis i'm nadredd ddathlu golau llachar gydag animeiddiad trosbennu.
Defnyddiwch y rhaglen i wneud i'ch anifail anwes wneud sŵn i gael sylw os yw'r lefel sŵn yn llai na neu'n hafal i 50.
Gair o gyngor: Gosodwch floc saib (o leiaf 500 milieiliad) ar ôl i'ch sŵn chwarae - coeliwch fi.
Cofiwch sicrhau bod pa bynnag sŵn rydych chi wedi dewis ei ddefnyddio yn y rhaglen yn chwarae unwaith yn unig neu hyd nes ei fod wedi gorffen.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Nawr, gadewch i ni ddatblygu'r rhaglen ymhellach gyda'r tasgau canlynol.
Os yw eich anifail anwes yn cysgu wrth glywed sŵn uchel, rhaid iddo ymateb trwy ddangos mwy o ddicter/ofn/syndod na phan fydd yn effro.
Gair o gyngor: Gallwch roi os-datganiadau y tu mewn i'w gilydd, gan greu os-datganiad sydd wedi'i bentyrru.
Pwysig: Bydd eich rhaglen yn gweithio ei ffordd trwy'r rhestr o os-datganiadau a arall os-datganiadau yn y ddolen am byth. Bydd yn rhedeg y darn cyntaf o god os bodlonir yr amodau, ac yn gadael y gweddill.
Meddyliwch am hyn fel rhestr wirio lle rydych chi'n dychwelyd i frig y rhestr a dechrau eto ar ôl gwirio rhywbeth.
Mae hyn yn golygu bod angen i chi wirio pa un o'r amodau (sŵn uchel neu dywyllwch) sy'n dod gyntaf yn eich rhaglen a mewnosod y os-datganiad newydd yn yr amod perthnasol.
Defnyddiwch os ac arall ddatganiad ar gyfer hyn er mwyn penderfynu pa ymateb sŵn uchel sy'n cael ei ddangos.
Gan ein bod am glirio'r sgrin cyn y ddau opsiwn, gallwn ddefnyddio'r gorchymyn hwn unwaith cyn y os/arall-datganiad newydd.
Fel arall, gallech ystyried defnyddio blociau rhesymeg uwch sy'n caniatáu sawl amod mewn os/arall os-datganiad.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Yn ein rhaglen atebion, mae'r amod sŵn uchel uwchben yr amod tywyll, felly mae'r os-datganiad newydd yn mynd yno.
Mae angen i'ch newidyn 'llawnder' fod ag uchafswm gwerth o 5.
Gair o gyngor: : Mae hyn yn golygu eich bod ond eisiau ychwanegu un at y gwerth llawnder pan fydd yn llai na 5 (neu'n llai na ac yn hafal i 4).
Mae angen os-datganiad arnoch pan fydd y llawnder yn llai na 5 er mwyn ychwanegu at y gwerth pan fydd yn wir yn unig.
Ar hyn o bryd, does dim angen os-datganiad i wneud hyn gan nad oes unrhyw gam gweithredu ar gyfer os-datganiad nad yw'n wir.
Cofiwch gadw'r os-datganiad hwn y tu allan i unrhyw ddolennau ailadrodd a ddefnyddir ar gyfer yr animeiddiad bwydo.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Yn hytrach na dangos gwerth llawnder i'r defnyddiwr gan ddefnyddio'r mewnbwn a ddewiswyd yn yr heriau arian, defnyddiwch y rhaglen i ddangos lefel mesurydd.
Gair o gyngor: Gallwch roi arall os-datganiadau y tu mewn i os / arall os / arall-datganiad.
I wneud hyn, bydd angen delwedd ar gyfer pob lefel lawnder i greu effaith mesurydd/medrydd.
Mewn rhestr datganiadau o'r fath, mae angen i chi gynnwys arall-datganiad i gofnodi 0 a/neu unrhyw werthoedd annisgwyl. Gall hyn weithredu fel sgrin gwall i ni wedyn.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Fe wnaethom ddewis siâp mesurydd crwn sy'n mynd yn fwy cyflawn pan fydd y lefel lawnder yn uwch.
Gair o gyngor: Gallai helpu i symud yr animeiddiad bwyta i'r un os-datganiad â phan fydd y newidyn llawnder yn cynyddu, gan sicrhau o ganlyniad bod gennych animeiddiad gwahanol pan fydd arall-datganiad yn llawn.
Cofiwch fod angen dolennau ailadrodd y tu mewn i'r datganiadau hyn er mwyn ailadrodd animeiddiadau.
Wrth ddatblygu rhaglen, yn aml mae'n rhaid i ni newid lleoliadau adrannau cod er mwyn cynnwys nodweddion newydd.
I wneud hyn, mae angen atodi 'arall' i'n datganiad 'os llawnder < 5'.
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Dylai'r gwerth llawnder ostwng yn araf dros amser wrth i chwant bwyd eich anifail anwes gynyddu eto.
Gair o gyngor: Gan fod hon yn broses gefndirol na fydd yn dioddef ymyrraeth gan y ddolen am byth, gallwch ddefnyddio dolen amserydd ar wahân i wneud hyn.
Gallwch ddod o hyd i floc amserydd yn y ddewislen Dolennau.
Yr amser diofyn yw 500 ms - sef bob hanner eiliad - bydd angen i chi newid hyn (fe wnaethom ni weld bod munud - neu 60000 ms - yn addas iawn ar gyfer hyn).
Rydym am dynnu un i ffwrdd o'r llawnder fel y gallwn ddefnyddio bloc 'newid llawnder gan' gyda -1 yn hytrach nag 1.
Dydyn ni ddim eisiau gwerthoedd negyddol, felly rydym ond eisiau tynnu i ffwrdd o'r gwerth llawnder os yw dros 0 (neu'n fwy nag 1 ac yn hafal i 1).
Os ydych chi'n dal i gael trafferth, defnyddiwch y botwm ateb isod.
Mae gennych chi nawr anifail anwes rhithwir. Dyma rai syniadau ar gyfer ychwanegiadau a nodweddion eraill y gallwch chi roi cynnig arnyn nhw. Gweithgareddau i chi ymchwilio iddyn nhw a'u harchwilio yw'r rhain - does dim atebion ar gael.
Defnyddiwch y rhaglen i wneud i'r anifail anwes ddangos pan fydd chwant bwyd arno (llawnder ≤ 1).
Gair o gyngor: Gellir gwneud hyn trwy ychwanegu arall os-datganiad i'ch dolen am byth.
Ychwanegwch lefel hapusrwydd a mewnbynnau chwarae yn y rhaglen. Mwya'n byd y byddwch chi'n chwarae gyda'r anifail anwes, hapusa'n byd fydd e'n teimlo.
Gair o gyngor: Efallai y byddwch am symud y mesurydd chwant bwyd fel ei fod yn dangos yn awtomatig ar ôl bwydo'r anifail anwes er mwyn rhyddhau botwm B ar gyfer hyn.
Gosodwch werth uchaf ac amser oeri ar gyfer y gwerth hapusrwydd. Sut fydd eich anifail anwes yn ymateb pan fydd y gwerth hapusrwydd yn gostwng yn rhy isel?
Gair o gyngor: Bydd hyn yn defnyddio'r un fframwaith â'n mesurydd llawnder.
Defnyddiwch y rhaglen fel bod yr anifail anwes yn tyfu dros amser os yw'n derbyn gofal priodol.
Gair o gyngor: Gallech greu newidyn sgôr ar gyfer hyn a threfnu bod yr anifail anwes yn gwella wrth i'r sgôr gyrraedd nodau penodol.
Gwers Fideo (yn Saesneg):
Ymarferion:
Ar gyfer y sesiwn hon byddwn ni'n creu gêm gornest dis ar gyfer dau chwaraewr gan ddefnyddio dau BBC Micro:Bit. Rydym yn argymell defnyddio'r multi-editor ar gyfer yr ymarferion hyn. Enwch y rhaglen ar y chwith yn Chwaraewr Un a'r rhaglen arall yn Chwaraewr Dau.
Fel sy'n wir am bob un o'n hymarferion, mae dysgwyr yn cwblhau un lefel cyn symud i'r nesaf. Oni wneir hynny, mae'n bosibl y bydd dysgwyr yn methu derbyn gwybodaeth neu'n hepgor cam hanfodol sy'n atal y rhaglen rhag gweithio.
Cliciwch ar bennawd pob her i gael y manylion.
Ewch ati i raglennu'r ddau Micro:Bit i ddangos rhif ar hap rhwng 1 a 6 bob tro y caiff ei ysgwyd - fel rholio dis.
Gair o gyngor: Er mwyn osgoi ymyrraeth rhwng dolenni, mae angen i'r holl allbynnau fod y tu mewn i'r ddolen am byth.
Roedd y fideo ar gyfer Sesiwn Dau yn cynnwys gwybodaeth am sut i greu rhaglen ddis sylfaenol.
Defnyddiwch enw newidyn rholio dis gwahanol ar gyfer pob chwaraewr - bydd hyn yn lleihau dryswch yn nes ymlaen.
Dim ond ar ôl rholio'r dis am y tro cyntaf y byddwch am i werth y dis ddangos (felly pan nad yw'r newidyn yn 0 bellach).
Chwaraewr Un
Chwaraewr Dau
Ar gyfer Chwaraewr Un, gwnewch i fotwm A ddangos eich sgôr diwethaf ar ôl rholio'r dis tra bod botwm B yn dangos sgôr diwethaf y chwaraewr arall. Gwnewch yr un peth ar gyfer Chwaraewr Dau.
Gair o gyngor: Cofiwch osod y ddau Micro:Bit yn yr un grŵp radio er mwyn iddynt allu siarad â'i gilydd - dylid gwneud hyn yn ystod y dilyniant cychwyn.
Defnyddiwch os-datganiadau y tu mewn i'r ddolen am byth er mwyn pwyso botwm, yn hytrach na'r blociau 'ar fotwm A wedi'i wasgu' neu 'ar fotwm B wedi'i wasgu' ar wahân.
Cofiwch, gallwch bentyrru os-datganiadau y tu mewn i'w gilydd.
Gallwch greu arall-datganiad nad yw'n cynnwys unrhyw beth, neu gallwch ei ddefnyddio i adrodd gwall.
Chwaraewr Un
Chwaraewr Dau
Pan fydd y naill chwaraewr neu'r llall yn pwyso'r logo cyffwrdd, gwnewch i'r sgrin ddangos cryfder y signal.
Mae'r logo cyffwrdd ar gael ar Micro:Bit V2 yn unig - felly edrychwch ar adran V2 o'r ddewislen fewnbynnu.
Mae'n anodd profi hwn yn yr efelychydd oherwydd dim ond pan fydd yn anfon gwybodaeth y gellir newid cryfder y signal (yn yr achos hwn pan fyddwn yn ei ysgwyd).
Chwaraewr Un
Chwaraewr Dau
Dylai pwyso botwm A a B ar yr un pryd roi cyfanswm y ddau chwaraewr ar ôl rholio'r dis.
Gair o gyngor: Bydd angen i chi gael rhywbeth i wirio bod y ddau chwaraewr wedi rholio'r dis.
Pwysig: I wirio yn erbyn dau amod (yn yr achos hwn, bod y ddau chwaraewr wedi rholio'r dis), gallech bentyrru'r os-datganiadau neu ddefnyddio bloc 'and'.
Amodau wedi'u Pentyrru
Gweithredwr Boole 'a'
Noder: Mae gwerth Boole yn wir neu'n anwir. Mae Gweithredwr Boole yn cymharu dau fewnbwn i greu un allbwn gwir neu anwir.
Gair o gyngor:Mae angen gosod y datganiad 'os btwm A a B yn cael ei wasgu' yn y ddolen am byth uwchben y os-datganiadau ar gyfer botwm A a B.
Pwysig: Wrth ddefnyddio datganiadau 'arall os', mae'r rhaglen yn mynd trwy'r rhestr o amodau ac yn stopio wrth yr amod cyntaf sy'n wir. Yna bydd yn hepgor y gweddill. Wrth ddefnyddio 'os btwm A a B yn cael ei wasgu', mae unrhyw amodau sy'n gwirio a yw'r naill fotwm neu'r llall yn cael ei bwyso yn dod yn wir. Felly, bydd 'os botwm A yn cael ei wasgu' yn wir, bydd 'os botwm B yn cael ei wasgu' yn wir a bydd 'os botwm A+B yn cael ei wasgu' yn wir. Mae hyn yn amlygu pwysigrwydd gosod amodau mewn trefn.
Mae'r ddewislen Mathemateg yn cynnwys blociau sy'n gwneud y cyfrifiadau i ni.
Efallai yr hoffech ychwanegu arall-datganiad er mwyn dangos nad yw pob chwaraewr wedi rholio'r dis eto.
Symudwch y rhaglen ar gyfer botwm A er mwyn i'r Micro: Bit ddangos rhif y dis ar y sgrin yn awtomatig, a chynnwys arall-datganiad ar gyfer gwerth sero ar y dis. Gallai hyn fod yn animeiddiad, delwedd, neu neges/cyfarwyddyd sydd i ymddangos.
Gair o gyngor: Bydd angen saib arnoch nawr er mwyn cadw gwerthoedd heblaw rhif dis y chwaraewr ei hun ar y sgrin am gyfnod hirach.
Gallwch symud rhaglen dangos y chwaraewr ei hun i'r arall-datganiad ar gyfer hyn.
Defnyddiwch saib 1 eiliad (1000ms) lle bo angen.
Mae'n bosibl y bydd angen i chi bwyso botymau am ychydig mwy o amser wrth brofi. Bydd hyn yn berthnasol iawn os ydych chi'n defnyddio testun i ddangos neges gan na fydd yn gwrando am fotymau nes bod y neges wedi gorffen sgrolio.
Gadewch y datganiad 'arall os botwm A yn cael ei wasgu wedyn' yn wag am y tro.
Chwaraewr Un
Chwaraewr Dau
Nawr defnyddiwch fotwm A i ailosod y gêm.
Gair o gyngor: Bydd angen i chi anfon y gorchymyn ailosod i Micro:Bit y chwaraewr arall hefyd.
Gallwch anfon testun, fel gair, dros y grŵp radio.
Os ydych chi'n defnyddio testun ar gyfer hyn, mae angen i chi ddefnyddio'r bloc cymharu testun - dyma'r bloc sydd â dyfynodau y tu mewn i'r bocsys gwerth.
Fel arall, gallech anfon rhif gwahanol sy'n sbarduno'r gorchymyn ailosod.
Cofiwch gadarnhau eich bod yn defnyddio'r blociau derbyn cywir ar gyfer y math o wybodaeth rydych chi'n ei hanfon.
Chwaraewr Un
Chwaraewr Dau
Mae'n amser cynnal gornest rhwng y chwaraewyr. Yr enillydd yw'r chwaraewr sy'n rholio'r dis â'r sgôr uchaf. Gwnewch i'r Micro:Bits ddangos a wnaeth eu chwaraewr ennill neu golli.
Gair o gyngor: Gallwch ddefnyddio'r gweithredydd Boole 'and' yma i sicrhau bod y ddau chwaraewr wedi rholio'r dis cyn gweld pwy sydd wedi ennill.
Mae angen i chi benderfynu ble i osod hyn yn eich rhaglen.
Cymharwch sgôr dis y ddau chwaraewr i gyfrifo pa un yw'r uchaf.
Beth sy'n digwydd pan fydd y ddau chwaraewr yn rholio'r un rhif?
Gallwch ddefnyddio delweddau, testunau, a/neu animeiddiadau ar gyfer y rhain.
Ychwanegwch seibiau lle mae angen eu cynnwys yn eich barn chi.
Chwaraewr Un
Chwaraewr Dau
Uwchraddio'r rhaglen fel bod yn rhaid i'r ddau chwaraewr rolio'r dis dwywaith cyn cymharu eu cyfansymiau i benderfynu pwy sydd wedi ennill. Ni ddylai chwaraewyr allu rholio mwy na dwywaith.
Gair o gyngor: Bydd angen newidyn newydd arnoch ar sail sawl gwaith y mae'r dis yn cael ei rolio.
Bydd angen defnyddio'ch newidyn rhifo newydd yn lle'r holl amodau sy'n cadarnhau ar hyn o bryd a yw cyfanswm dis y chwaraewr ei hun dros 0.
Gwnewch i neges neu ddelwedd ymddangos os yw chwaraewr yn ceisio rholio'r dis mwy na dwywaith - bydd yn haws profi hyn wedyn.
Gellir defnyddio'r ddolen 'ar ysgwyd' i ddefnyddio a newid newidyn rhifo.
Bydd angen i chi osod y newidyn newydd hwn i sero yn y dechrau ac yn ystod y broses ailosod.
Ni fydd newid y rhif ar hap fel ei fod rhwng 1 a 12 neu luosi'r rhif cyntaf a roliwyd â dau yn cyfateb i'r un tebygolrwydd â rholio'r dis ar wahân dwywaith - felly, bydd angen i chi ddefnyddio newidyn cyfrif dis. Am ragor o wybodaeth am debygolrwydd rholio'r dis, gallwch edrych ar ein gweithgaredd Gornest Ddisiau.
Chwaraewr Un
Chwaraewr Dau
Dyma rai nodweddion ychwanegol y gallwch eu cynnwys yn eich gêm ornest dis. Gweithgareddau i chi ymchwilio iddynt a'u harchwilio yw'r rhain - nid oes atebion ar gael.
Ychwanegwch gyfarwyddiadau i sgriniau chwaraewr.
Gair o gyngor: Defnyddiwch gyfarwyddiadau byr neu ar ffurf lluniau.
Defnyddiwch system sgôr sy'n olrhain sawl gwaith y mae pob chwaraewr wedi ennill neu golli.
Gair o gyngor: Gallwch ddisodli'r rhaglenni ar gyfer botwm neu ddefnyddio'r synhwyrydd cyffwrdd.
Rhowch wybod i'r chwaraewyr os ydyn nhw'n ysgwyd y Micro:Bit yn rhy galed.
Gair o gyngor: I wneud hyn, mae angen mesur cyflymiad y Micro:Bit, ac mae unrhyw beth dros werth cryfder o 1700mg yn ormod.
Ychwanegwch animeiddiadau wrth rolio'r dis.
Allwch chi ddylunio fersiwn o'r gêm hon ar gyfer dau chwaraewr gan ddefnyddio un BBC Micro:Bit yn unig?
Gair o gyngor: Ni fydd angen unrhyw gyfathrebu radio i wneud hyn.
Gwers Fideo (yn Saesneg):
Ymarferion:
Ar gyfer y sesiwn hon byddwn yn creu rhaglen goleuadau traffig gan ddefnyddio stribed Neopicsel.
Fel sy'n wir am bob un o'n hymarferion, mae dysgwyr yn cwblhau un lefel cyn symud i'r nesaf. Oni wneir hynny, mae'n bosibl y bydd dysgwyr yn methu derbyn gwybodaeth neu'n hepgor cam hanfodol sy'n atal y rhaglen rhag gweithio.
Cliciwch ar bennawd pob her i gael y manylion.
Defnyddiwch y blociau sydd wedi'u darparu gan yr estyniad Neopicsel i gysylltu stribed 24 LED i bin 1.
Gair o gyngor: Cofiwch greu eich dilyniant cychwyn eich hun ar gyfer y rhaglen newydd hon er mwyn gallu ei hadnabod.
Mae'r cam hwn yn rhan o'r broses o sefydlu eich rhaglen, felly mae angen defnyddio'r bloc 'ar ddechrau' i wneud hyn.
Gosodwch 3 ystod o faint cyfartal er mwyn ail-greu goleuadau traffig gan roi coch ar y brig, melyn yn y canol, a gwyrdd ar y gwaelod.
Gair o gyngor: Mae'r rhifau stribed LED yn dechrau ar 0.
Mae modd rhannu 24 â 3, sy'n golygu y bydd angen i chi sicrhau bod yr ystodau yn cwmpasu 8 LED yr un.
Defnyddiwch y rhaglen i greu goleuadau traffig sy'n symud trwy ddilyniant croesi dro ar ôl tro - mae'r golau yn goch am 10 eiliad, yn goch a melyn am 5 eiliad, yn wyrdd am 10 eiliad, ac yna'n felyn am 5 eiliad.
Trwy osod y dilyniant hwn yn y ddolen am byth bydd modd sicrhau ei fod yn ailadrodd yn am byth.
Cofiwch ddiffodd y lliwiau nad oes eu hangen bob tro (eu gosod i ddu).
Symudwch bob newid golau i'w swyddogaethau eu hunain, gan gofio eu galw yn y ddolen am byth wedyn.
Rhowch enw addas i bob swyddogaeth.
Ychwanegwch animeiddiadau i'r Micro:Bit i ddangos pryd y mae'n ddiogel ac yn anniogel i gerddwyr groesi'r ffordd. Defnyddiwch dair swyddogaeth newydd i wneud hyn - un ar gyfer cerdded, un ar gyfer aros, ac un i rybuddio bod y goleuadau'n newid i wyrdd ar gyfer y traffig.
Gair o gyngor: Bydd angen i chi amseru eich animeiddiad i ddisodli'r defnydd presennol o flociau saib ar gyfer amseru'r goleuadau.
Gair o gyngor: Bydd newidyn yn golygu mai dim ond un swyddogaeth sydd ei hangen arnoch i aros, a gellir ei defnyddio pan fydd y golau yn wyrdd a phan fydd yn felyn.
Mae hwn yn gyfle da i ymarfer gweithio gyda'r blociau ailadrodd oddi mewn i'r swyddogaethau.
Gallwch alw swyddogaeth o'r tu mewn i swyddogaeth arall.
Os ydych chi'n defnyddio dwy ddelwedd ar gyfer eich animeiddiadau, bydd angen i chi eu hailadrodd 10 gwaith gyda seibiau hanner eiliad ar ôl pob un ar gyfer y golau coch a'r golau gwyrdd. Mae angen ailadrodd 5 gwaith yn unig pan fydd y golau melyn yn weithredol.
Defnyddiwch y rhaglen i greu newidyn lliw golau traffig i'w ddefnyddio i nodi pa olau sy'n weithredol ar hyn o bryd a defnyddiwch hyn yn y datganiadau 'os/arall' er mwyn gosod y goleuadau.
Gair o gyngor: Cofiwch osod y newidyn yn y bloc 'ar ddechrau'.
Bydd angen i chi ddefnyddio rhifau i gynrychioli gosodiadau gwahanol y goleuadau.
Defnyddiwch arall-datganiad i nodi unrhyw wallau yn ymwneud â gwerth y newidyn.
Defnyddiwch y botwm A ar y Micro:Bit i atal y traffig.
Gair o gyngor: Dim ond tra bod y goleuadau traffig yn wyrdd y mae angen i'r swyddogaeth ddisodli hon weithio.
Pwysig: Gallwch atal dolen yn gynnar trwy ddefnyddio'r bloc 'break' yn y ddewislen Dolenni.
Mae angen i chi ddweud wrth y rhaglen am newid i felyn pan fydd botwm A yn cael ei bwyso.
Er mwyn disodli'r rhaglen yn y modd hwn, bydd angen i chi gadarnhau bod botwm A wedi'i bwyso y tu mewn i floc ailadrodd yr animeiddiad perthnasol.
Mae'n bosibl y bydd angen i chi wirio yn erbyn newidyn arall hefyd; gall hyn ddefnyddio os-datganiad wedi'i bentyrru neu weithredwr Boole 'a'.
Ychwanegwch sain i nodi pryd mae'n ddiogel i groesi ar gyfer y rhai na allant weld y cyfarwyddiadau gweledol.
Y cwbl sydd angen ei wneud yw chwarae un nodyn pan fydd pob delwedd yn yr animeiddiad yn newid er mwyn dangos ei bod yn ddiogel dechrau croesi (pan fydd y goleuadau traffig yn goch).
Nod yr ymarferiad isod yw ehangu'r rhaglen ymhellach. Gweithgaredd i chi ymchwilio iddo a'i archwilio yw hwn - nid oes atebion ar gael.
Ychwanegwch ail Neopicsel i bin 2 ac ewch ati i wneud iddo weithredu fel goleuadau traffig ar gyfer traffig sy'n llifo i'r cyfeiriad arall.
I ba raddau gallwch chi dacluso eich cod trwy ddefnyddio swyddogaethau, dolennau wrth, blociau ailadrodd, a newidynnau?
Gwers Fideo (yn Saesneg):
Ymarferion:
Ar gyfer y sesiwn hon byddwn yn creu rhaglen i droi eich BBC Micro:Bit yn fesurydd sain trwy ddefnyddio serfo.
Fel sy'n wir am bob un o'n hymarferion, mae dysgwyr yn cwblhau un lefel cyn symud i'r nesaf. Oni wneir hynny, mae'n bosibl y bydd dysgwyr yn methu derbyn gwybodaeth neu'n hepgor cam hanfodol sy'n atal y rhaglen rhag gweithio.
Cliciwch ar bennawd pob her i gael y manylion.
Ysgrifennwch raglen sy'n canu larwm pan fydd lefel y sain dros 200.
Gair o gyngor: Cofiwch am y drefn 'start-up' i adnabod y rhaglen.
Mae angen defnyddio os-datganiad gydag amod lefel sain > 200.
Mae yna floc newidiol ar gyfer lefel y sain yn y ddewislen Mewnbwn ar gyfer y V2.
Ychwanegwch rai oediadau i leihau cyfradd y sain/nodyn o'ch dewis.
Defnyddiwch y rhaglen fel bod Micro:Bit yn arddangos lefel y sain ar ei sgrin.
Gair o gyngor: Gallwch wneud hyn trwy ddefnyddio bloc 'dangos testun'.
Mae angen rhoi'r bloc hwn yn y ddolen am byth, y tu allan i'r os-datganiad presennol.
Nodwch fod y bloc 'dangos testun' yn arafu sŵn y larwm. Gadewch i ni ddatrys hyn trwy ddisodli'r rhif â'r delweddau a'r amodau hyn:
Lefel y sain yw 0.
Mae lefel y sain dros 0 ac yn llai na neu'n hafal i 51.
Mae lefel y sain dros 51 ac yn llai na neu'n hafal i 102.
Mae lefel y sain dros 102 ac yn llai na neu'n hafal i 153.
Mae lefel y sain dros 153 ac yn llai na neu'n hafal i 204.
Mae lefel y sain dros 204.
Dylai'r larwm ddim ond canu pan fydd y mesurydd yn llawn.
I wneud hyn, bydd angen cyfres newydd o ddatganiadau 'os' ac 'arall os'.
Cofiwch y gallwch ddefnyddio'r gweithredwr Boole 'a' yn hytrach na phentyrru os-datganiadau.
Defnyddiwch y arall-datganiad ar y diwedd ar gyfer unrhyw wallau yn y rhaglen.
Ychwanegwch serfo lleoliad 180° at bin 1. Ewch ati i raglennu'r serfo i orffwys ar 0° tra bod lefel y sain yn llai na neu'n hafal i 102. Fel arall, mae angen iddo symud i 180°.
Gair o gyngor: Bydd angen i chi ddefnyddio'r estyniad i'r serfo.
Gallwn ddefnyddio'r holl osodiadau diofyn ar gyfer y serfo lleoliad i wneud hyn. Fodd bynnag, mae gosod y serfo i safle cychwyn (0° yn yr achos hwn) yn y bloc 'ar ddechrau' yn parhau i fod yn arfer da.
Bydd angen i chi osod ongl y serfo ym mhob os-/arall-datganiad .
Wrth brofi, cofiwch sicrhau eich bod yn rhoi amser i'r serfo gwblhau ei gylchdro - os ydych chi'n newid yr amod yn rhy gyflym, ni fydd yn ymddwyn yn y modd rydym ni'n ei ddisgwyl.
Pan fydd y serfo yn newid cyfeiriad, allwch chi sicrhau bod y serfo ddim ond yn symud 10° bob 300 milieiliad? Mae hyn yn lleihau'r straen ar y serfo, gan ei atal rhag torri - rhywbeth nad yw'r efelychydd yn ei efelychu.
Gair o gyngor: Bydd angen i chi sicrhau nad yw'r serfo yn ceisio troi o dan 0° neu dros 180° - gallai hyn dorri eich serfo.
Bydd angen i chi greu newidyn ar gyfer yr ongl - cofiwch osod hyn yn y bloc 'ar ddechrau'.
Gellir defnyddio'r newidyn newydd hwn i osod ongl y serfo - gan gynyddu neu leihau'r ongl 10°.
Wrth osod amodau eich os-datganiad, dylech ystyried y gwerthoedd i'w defnyddio - gan ein bod yn symud 10° ar y tro, ystyriwch ddefnyddio 10 a 170.
Bydd angen i'r os-datganiadau newydd hyn ddisodli'r blociau serfo sydd wedi'u gosod ym mhob datganiad 'os/arall'.
Gan fod saib 200 milieiliad eisoes yn y datganiad > 204, mae angen i ni addasu'r symudiad i gyfanswm o 300.
Er mwyn tacluso ein cod, gadewch i ni symud cyfarwyddiadau'r serfo i'w swyddogaethau eu hunain a'u galw pan fydd angen.
Gair o gyngor: Bydd angen un i ostwng yr ongl ac un i gynyddu'r ongl.
Cofiwch fod y ddewislen Swyddogaethau ar gael yn yr adran Uwch.
Er mwyn cael dwy swyddogaeth yn unig - tynnwch y saib 200 milieiliad o'r rhaglen larwm fel bod y rhaglen hon yn gallu defnyddio'r saib 300 milieiliad yn y swyddogaeth serfo.
Cyn dechrau'r ymarferiad hwn, rydym yn eich cynghori i ddyblygu eich rhaglen gan y byddwn yn dileu llawer o'r cod blaenorol.
Cam 1. Caewch eich rhaglen a dychwelyd i dudalen hafan makecode.microbit.org.
Cam 2. Cliciwch ar yr opsiwn gweld popeth wrth ymyl 'Fy Mhrosiectau'.
Cam 3. Dewiswch y ffeil rydych chi am ei dyblygu (dylai tic gwyrdd ymddangos ar y ffeil).
Cam 4. Cliciwch ar yr opsiwn dyblygu ar ochr dde uchaf y sgrin. Bydd hyn yn caniatáu i chi ddewis enw ar gyfer eich copi newydd.
Cam 5. Agorwch eich copi newydd a pharhau â'r her nesaf.
Yn hytrach na chael un gwerth yn penderfynu symudiad y serfo, gallwn wneud i'r serfo weithredu fel nodwydd ar fesurydd sain (fel y dangosir isod), gan symud i'r ongl gywir ar gyfer lefel y sain ar hyn o bryd.
Pwysig:Mae gennym ystod o 0° i 180° ar y serfo ond mae gan lefel y sain ystod o 0 i 255. Mae dwy ffordd o wneud hyn:
Gwneud y gwaith mathemateg ein hunain
Cyfrifwch y pellter y mae angen i'r mesurydd symud ar gyfer un uned o sain:
(180 ÷ 255) = 0.7058823529411°
Defnyddiwch y gwerth uchod gyda bloc Mathemateg y tu mewn i floc 'gosod serfo'.
Defnyddiwch y bloc 'map'
Mae'r bloc map yn caniatáu i ni fynd i mewn i'r ystod rydym ni'n ei mesur (lefel sain) sef 0 i 255, a'i newid i ystod y serfo, sef 0 i 180. Yna mae'r bloc yn gwneud yr holl gyfrifiadau i ni.
Mae angen i ni ddileu'r swyddogaethau rydym ni wedi'u creu ar gyfer y serfo o'n rhaglen. Bydd y blociau 'galw' yn diflannu'n awtomatig pan fydd eu swyddogaeth yn cael ei dileu.
Cadwch animeiddiad y mesurydd sgrin yn ei le.
Y cwbl sydd ei angen ar gyfer hyn yw un bloc 'gosod serfo' gan ddefnyddio'r dull a ddewiswyd o'r uchod.
Mae'r ymarferion isod wedi'u cynllunio i ehangu eich dealltwriaeth o serfos. Gweithgareddau i chi ymchwilio iddynt a'u harchwilio yw'r rhain - nid oes atebion ar gael.
Yn hytrach na defnyddio'r mesurydd i fesur lefel y sain, gallwch ei ddefnyddio i fesur cryfder signal radio, gan osod larwm os yw'r signal yn mynd yn rhy wan.
Gair o gyngor: Bydd angen i chi ddod o hyd i'r ystod o werthoedd ar gyfer cryfder y signal radio.
Ydych chi'n cofio'r rhaglen goleuadau traffig y gwnaethom ni ei chreu yn y sesiwn ddiwethaf? Nawr gallwch ychwanegu croesfan rheilffordd gyda serfo yn gweithredu fel y rhwystr.
Gair o gyngor: Gallwch gysylltu'r serfo i binnau 0, 1 neu 2 yn unig. Fodd bynnag, gallwch adleoli'r Neopicseli i rifau pin eraill (hyd at 16).
Gwers Fideo (yn Saesneg):
Ymarferion:
Ar gyfer y sesiwn hon byddwn yn creu rhaglen i reoli croesfan reilffordd. Mae hyn yn cynnwys adolygu cyfathrebu radio, datganiadau-os, newidynnau, swyddogaethau, Neopixels, a serfos.
Rydym yn argymell eich bod yn rhoi cynnig ar yr heriau hyn gyda'r golygydd safonol.
Fel sy'n wir am bob un o'n hymarferion, mae dysgwyr yn cwblhau un lefel cyn symud i'r nesaf. Oni wneir hynny, mae'n bosibl y bydd dysgwyr yn methu derbyn gwybodaeth neu'n hepgor cam hanfodol sy'n atal y rhaglen rhag gweithio.
Cliciwch ar bennawd pob her i gael y manylion.
Ar gyfer yr ymarferion hyn, dychmygwch fod gennych chi un Micro:Bit i reoli'r groesfan tra bod un arall yn gweithio fel tywysydd ar y trên. Bydd y groesfan yn gwybod bod trên yn dod pan fydd cryfder signal y tywysydd yn cryfhau.
Defnyddiwch ddelwedd, animeiddiad a/neu destun i greu sgrin agoiadol sy'n ffordd o adnabod eich rhaglen.
Gair o gyngor: Os mai dim ond delwedd rydych chi'n ei defnyddio, cofiwch gynnwys oedi (500ms) er mwyn iddi aros ar y sgrin yn ddigon hir i'w gweld.
Ceisiwch beidio â gwneud i'r sgrin agoriadol gymryd gormod o amser, fel arall bydd hyn yn mynd yn rhwystredig yn ystod profion wrth i ni symud ymlaen.
Gwnewch i'r Micro:Bit anfon y rhif sero trwy radio o'r tu mewn i'r ddolen am byth.
Gair o gyngor: Peidiwch ag anghofio gosod grŵp radio i'ch Micro:Bit ei ddefnyddio.
Cewch hyd i'r blociau sydd eu hangen arnoch yn y ddewislen Radio.
Mae angen i chi sefydlu grŵp radio yn y dilyniant agoriadol.
Crëwch newidyn cryfder tywysydd a'i osod i'r cryfder signal sy'n cael ei dderbyn.
Gair o gyngor:: Er mwyn mesur cryfder y signal, mae angen i'r rhaglen dderbyn y rhif a anfonwyd yn gyntaf.
Dewiswch enw addas ar gyfer eich newidyn newydd. Mae rhai rhaglenni'n defnyddio llawer o newidynnau, ac mae'n fuddiol gallu adnabod pwrpas pob un yn gyflym.
Cofiwch osod eich newidyn newydd i 0 pan fydd y rhaglen yn dechrau - Mae hyn yn arfer da ar gyfer pan fyddwch chi'n dechrau dysgu ieithoedd rhaglennu sy'n seiliedig ar destun.
Bydd angen i chi osod eich newidyn newydd i werth cryfder signal a dderbynnir y tu mewn i floc 'ar dderbyn drwy radio'.
ar ddechrau
dangos leds
oedi (ms) 500 ⯆
radio gosod grŵp 33
gosod cryfderBeacon ⯆ i 0
am byth
radio anfon rhif 0
ar dderbyn drwy radio receivedNumber
gosod cryfderBeacon ⯆ i pecyn a dderbyniwyd cryfder signal ⯆
Nawr mae angen dwy swyddogaeth arnom, un ar gyfer y rhaglen pan fydd trên yn dod, a'r llall ar gyfer pan na fydd trên yn dod . Rhowch enw addas i bob swyddogaeth a rhoi delwedd wahanol ym mhob un.
Gair o gyngor: Ar gyfer profion yn unig mae'r delweddau ar hyn o bryd, felly bydd unrhyw un yn gwneud y tro.
Gellir dod o hyd i'r ddewislen Swyddogaethau yn yr adran Uwch.
Ni fydd y swyddogaethau hyn yn dangos wrth brofi, gan nad ydym wedi eu galw yn y rhaglen.
Galwch eich swyddogaeth ar gyfer pan fydd trên yn dod pan fydd cryfder y signal yn hafal i neu'n fwy na -75. Fel arall, galwch y swyddogaeth dim trên yn dod.
Gair o gyngor: Wrth wneud profion yn yr efelychydd, dylech drin y Micro:Bit uchaf fel rheolwr y groesfan a'r Micro:Bit isaf fel tywysydd y trên.
Bydd angen i chi greu datganiad OS ar gyfer hyn sy'n cymharu gwerth cryfder y tywysydd â -75.
Mae gan gryfder signal radio'r Micro:Bit yn yr efelychydd amrediad o -128 (signal gwannaf) i -42 (signal cryfaf).
Cofiwch fod nifer o symbolau mathemateg i ddewis ohonynt: = yn hafal i, < llai na, > yn fwy na, ≤ yn llai na neu'n hafal i, a ≥ yn fwy na neu'n hafal i.
Nawr mae angen i ni greu ein goleuadau croesi. Ar gyfer hyn rydym ni angen Neopixel wedi'i gysylltu â phin 1 wedi ei wneud o 15 LED.
Gair o gyngor: Bydd angen i chi ychwanegu'r estyniad Neopixel i'ch dewislen flociau.
Ewch yn ôl at Sesiwn Pedwar os ydych chi angen cofio sut i gael a defnyddio blociau estyniad Neopixel.
Bydd angen i chi newid y hyd diofyn o 24 i 15 LED.
Sefydlwch ddau amrediad, gydag enwau addas - un ar gyfer y 5 LED uchaf ac un arall ar gyfer y 5 LED isaf.
Gair o gyngor: Cofiwch fod cyfrif yn dechrau ar sero mewn cyfrifiadura.
Bydd yr amrediad cyntaf yn dechrau ar 0, tra bydd amrediad yr isaf yn dechrau ar 10.
Tynnwch y ddelwedd yn eich swyddogaeth ar gyfer pan fydd trên yn dod ac yn ei lle gosodwch raglen fydd yn rhoi'r goleuadau ymlaen a'u diffodd (bob yn ail rhwng y top a'r gwaelod) dair gwaith. Gosodwch saib o 500ms ar ôl rhoi bob golau ymlaen.
Gair o gyngor: Cofiwch fod gosod golau i ddu yn ei ddiffodd.
Bob tro mae golau yn cael ei roi ymlaen, mae angen i'r llall gael ei ddiffodd.
Gallwch ddefnyddio bloc 'ailadrodd 3 o weitiau' i fyrhau'r rhaglen.
Tynnwch y ddelwedd yn eich swyddogaeth ar gyfer pan nad yw trên yn agosáu a gosodwch raglen i sicrhau bod y goleuadau i gyd wedi'u diffodd.
Yn y swyddogaeth ar gyfer pan nad oes trên yn dod, bydd angen i chi osod ein dau amrediad golau ar ddu.
Gwnewch yn siŵr fod eich rhaglen yn chwarae nodyn C canol pan fydd y golau uchaf wedi ei roi ymlaen a nodyn E canol pan fydd y golau gwaelod wedi ei roi ymlaen. Dyma ein larwm i rybuddio gyrwyr a cherddwyr bod trên yn dod.
Gair o gyngor: Wrth brofi, gwnewch yn siŵr bod cryfder signal y Micro:Bit uchaf (ein 'croesfan') yn isel iawn neu gallai'r larymau ar y ddau Micro:Bit uno a/neu fod yn anghydamserol.
Ar gyfer rhwystr diogelwch croesfan y rheilffordd byddwn yn defnyddio serfo i reoli ei symudiad. Mae angen i hwn fod wedi ei gysylltu â phin 2 a bod yn y safle agored (0°) ar ddechrau'r rhaglen.
Gair o gyngor: Bydd hyn yn gofyn cael estyniad Servos.
Os ydych chi'n sownd, edrychwch yn ôl ar Sesiwn Pump.
Pan fydd trên yn agosáu, rydym am i'r goleuadau a'r larwm seinio dair gwaith ac yna i'r rhwystr diogelwch gau (symud i 90°).
Byddwch yn ofalus i beidio â rhoi'r cyfarwyddyd newydd hwn o fewn y ddolen ailadrodd.
Cofiwch mai ar bin 2 mae'r serfo.
Pan fo'r rhwystr diogelwch ar gau, mae angen i'r larwm stopio ac i'r goleuadau barhau i fflachio.
Gair o gyngor: Bydd arnoch chi angen ffordd i wirio ongl y serfo.
Bydd angen newidyn ongl serfo.
Bydd angen diweddaru'r newidyn newydd hwn bob tro mae'r rhwystr diogelwch yn agor neu'n cau.
Bydd angen diweddaru'r newidyn newydd hwn bob tro mae'r rhwystr diogelwch yn agor neu'n cau.
Pan fo'r rhwystr diogelwch ar gau, gwnewch i'r golau barhau i fflachio. Cyn belled â bod y rhwystr i lawr, bydd hyn yn dal i ailadrodd, felly does dim angen i chi ddefnyddio bloc ailadrodd yma.
Ar ôl i'r trên fynd heibio ac i signal y tywysydd bylu i lai na 75 eto, rydym ni eisiau i'r rhwystr diogelwch agor (a mynd yn ôl i 0°).
Gair o gyngor: Cofiwch ailosod eich newidyn ongl newydd hefyd ar yr un pryd.
Gallwch ddefnyddio'r newidyn ongl i roi gwybod a oes angen agor y giât. Mae hyn yn groes i'r gwiriad rydym ni wedi'i wneud yn barod i weld a oes angen ei chau.
Peidiwch ag anghofio bod ein serfo wedi ei gysylltu i bin 2.
Ar hyn o bryd, mae'r serfo'n symud yn rhy gyflym. Gallai hyn achosi anaf i gerddwr neu niweidio cerbyd sy'n mynd heibio. Felly rydym ni angen i'r rhwystr diogelwch ostwng 5° bob 200ms. Pan fydd yn agor, mae'n fwy diogel mynd yn gyflymach - yn yr achos hwn 20° bob 300ms.
Gair o gyngor: Rhowch y ddau olau coch ymlaen yn llawn yn ystod y symudiadau yma gan y bydd y fflachio'n diffodd yn ystod y symudiadau hyn.
Bydd ar ein swyddogaeth ar gyfer pan fydd ein trên yn dod angen arall os-datganiad ar gyfer pan fydd y rhwystr diogelwch wedi ei gau yn rhannol.
Bydd angen i chi ddefnyddio'r newidyn ongl yn yr amodau mathemateg.
Cofiwch y gallwch hefyd ddefnyddio'r bloc Boole 'a' a ddangoswyd eisoes os hoffech chi wirio yn erbyn dau werth.
Creu swyddogaethau newydd ar gyfer y symudiadau agor a chau efallai. Ydy, mae'n bosib galw swyddogaeth o fewn swyddogaeth arall.
Wrth agor y rhwystr diogelwch, byddwch yn ymwybodol na ellir rhannu 90 gyda 20. Meddyliwch sut y gallwch sicrhau bod y rhwystr yn agor yn llawn heb fynd yn rhy bell a thorri'r serfo.
Mae'r adran hon yn weithgaredd ychwanegol i chi roi cynnig arno - bydd yn gyfle i chi wneud ychydig o waith adolygu yn ogystal â chyflwyno rhai blociau a thermau newydd i chi.
Fel sy'n wir am bob un o'n hymarferion, mae'n well cwblhau'r tasgau yn eu trefn.
Dewiswch bennawd i ehangu.
Ewch ati i greu rhaglen rholio dis sylfaenol ar eich Micro:Bit. Dylai hyn ddangos rhif ar hap rhwng 1 a 6 ar y sgrin pan gaiff ei ysgwyd.
Gair o gyngor: Cofiwch eich sgrin cychwyn.
Os ydych chi'n cael problemau, ewch yn ôl i sesiynau dau a thri.
Nid oes angen dolen am byth ar gyfer hyn.
Yn hytrach na dangos rhif, mae'r sgrin yn dangos y delweddau canlynol gan ddibynnu ar y gwerth a gafodd ei rolio.
Un
Dau
Tri
Pedwar
Pump
Chwech
Gair o gyngor: Bydd angen i chi greu newidyn er mwyn dal gwerth y dis ar ôl ei rolio.
Bydd angen os/arall os datganiad gwahanol ar gyfer pob gwerth posibl. Yna gallwch ddefnyddio'r arall-datganiad i ddal unrhyw gamgymeriadau.
Mae Magic 8 Ball yn debyg i ddis, ond yn hytrach na chreu rhifau, mae'n creu atebion pan gaiff ei ysgwyd.
Yn hytrach na dangos rhifau yn eich rhaglen, ewch ati i wneud i Micro:Bit ddangos yr atebion oes, nac oes, efallai, ewch amdani, syniad da, syniad gwael, ddim yn gwybod, yn bendant, na yn bendant, a dim syniad.
Gair o gyngor: Mae 10 opsiwn erbyn hyn.
Ar gyfer y chwe opsiwn cyntaf gallwch chi ddisodli'r delweddau presennol.
Yna bydd angen i chi ychwanegu pedwar 'arall os' datganiad arall.
Cofiwch newid y swyddogaeth sy'n creu rhif ar hap i gael 10 opsiwn yn hytrach na 6.
Gallem fod wedi ymdrin â'r rhaglen hon mewn ffordd wahanol. Gallem fod wedi defnyddio rhywbeth o'r enw arae. Gellir dod o hyd i flociau arae yn y ddewislen Uwch.
Mae arae yn fath arbennig o newidyn. Yn hytrach na dal un darn o wybodaeth yn unig fel y newidynnau rydym wedi'u defnyddio, mae'n gallu dal rhestr o werthoedd/testunnau.
Yna gallwch alw gwerth o'r arae ar sail ei leoliad yn y rhestr. Fel sy'n wir am y rhan fwyaf o waith codio, mae rhifo eitemau yn y rhestr yn dechrau ar sero.
Enghraifft:
Gadewch i ni feddwl am ysgrifennu rhaglen sy'n dewis testun ar hap o restr sy'n cynnwys afal, oren, a banana pan fyddwn yn pwyso botwm A.
Fel sy'n wir am unrhyw newidyn, mae angen i ni osod yr arae yn yr adran 'ar ddechrau':
Gallwn ychwanegu neu dynnu eitemau o'r arae trwy ddefnyddio'r botymau plws a minws ar y bloc.
Er mwyn gwneud i'r sgrin ddangos eitem ar hap o'r arae, gallwn ddefnyddio'r bloc 'dangos testun' ynghyd â bloc arae 'cael gwerth ar hap o'.
Nawr mae gennym raglen gyflawn sy'n dewis eitem o'r rhestr ar hap a'i dangos ar y sgrin pan fyddwn yn pwyso botwm A.
Mae gan y rhaglen Magic-8 Ball un newidyn sydd â rhestr o testunnau gwahanol (yr atebion), felly gallem ddefnyddio arae a gwneud i'r rhaglen ddewis ar hap o restr yn hytrach na defnyddio os/arall os/arall datganiad mor fawr.
Pwysig: Ni ellir defnyddio araeau i ddisodli pob datganiad 'os' ac 'arall os'. Ar gyfer Makecode, gellir dim ond eu defnyddio ar gyfer rhestrau o testunnau neu rifau. Er enghraifft, ni allech ddefnyddio hyn ar gyfer y rhaglen ddis gyda delweddau gwahanol ar gyfer pob gwerth.
Newidiwch eich rhaglen Magic-8 Ball i ddefnyddio arae ar gyfer yr holl atebion posibl a dewis ar hap ohono pan gaiff ei ysgwyd.
Gair o gyngor: Gallech ddyblygu eich ffeil yn gyntaf er mwyn eu cymharu yn nes ymlaen.
Defnyddiwch y rhaglen rhestr ffrwythau enghreifftiol gan ddisodli'r ffrwythau ag atebion y Magic-8 Ball a ddarparwyd yn yr ymarferiad arian.
Cofiwch sicrhau eich bod yn defnyddio'r bloc rhestr testun, oherwydd bydd y fersiwn rhif yn creu gwall os ydych chi'n ychwanegu geiriau.
Cofiwch, gallwch ychwanegu mwy o eitemau at yr arae trwy ddefnyddio'r symbol plws ar y bloc sefydlu.
Ailenwch y rhestr gan ddewis rhywbeth sy'n fwy addas na ffrwythau.
Os nad ydych wedi gwneud hyn eisoes, ewch ati i ail-gynllunio'r dilyniant cychwyn ar gyfer y Magic-8 Ball yn hytrach na'r dis.
A chithau nawr wedi darganfod swyddogaethau ar hap trwy ddefnyddio araeau, gallwch greu nifer o bethau hynod ddifyr eraill. Dyma rai syniadau.
Swyddogaeth dewis gwirfoddolwr - gallwch greu arae sy'n cynnwys enwau pawb yn eich dosbarth, a'r tro nesaf nad oes neb yn gwirfoddoli, gallwch ei defnyddio i ddewis rhywun ar hap.
Rhaglen ysgrifennu creadigol - defnyddio cyfres o araeau i helpu i lunio syniad am stori. Er enghraifft, gallech ddatblygu swyddogaeth i greu lleoliad/genre/cymeriad/cynorthwydd ar hap.
Ap anhrefn siopa - rhowch eich rhestr siopa i mewn i arae ac yna defnyddiwch y swyddogaeth ar hap i benderfynu ar drefn eich siopa.
Gair o gyngor: Gallech wneud rhywfaint o waith ymchwil yn ymwneud â sut i waredu eitemau o arae ar ôl iddynt ymddangos.
We have adapted the material created for our Robotics Club for anyone to work through at home or in school.
Each of the below sessions include a video lesson from one of our staff and a set of exercises to assess your understanding. As this page is for independent learners, answers are included.
Please select a session heading to get started.
Video Lesson:
Exercises:
We have created three levels (bronze, silver, and gold) of challenge for learners to start investigating and creating programs in Microsoft Makecode.
All learners should start with the bronze level and work their way up as far as they can.
Click on each challenge heading to expand.
Create a program (in Makecode) that does the following:
When the program starts, have the LEDs show an image of your choice.
Tip: To delete blocks press delete on your keyboard or drag them back into the menu.
You can use an existing image with the 'show icon' block or create your own image using the 'show leds' block.
If you are using the 'show leds' block, you can click on the squares to select if they are lit or not.
As you only want this to show up when the program starts, you should put it inside the 'on start' block.
If you are still stuck, use the answer button below.
Using the 'show leds' block:
on start
show leds
Using the 'show icon' block:
on start
show icon
⯆
After the start-up is complete, have your program play an animation over and over until you stop the program.
Tip: An animation is a series of images that makes an object look like it is moving.
You will need to use the 'forever' block for this.
A basic animation could be produced using only two images.
As an example, try using the show icon block for the large heart followed by the small heart. This will create an animation that looks like a beating heart.
A series of images making an animation do not need pauses unless you wish to slow the motion down.
You can use the 'show leds', 'show icon', or a mix of the two.
If you are still stuck, use the answer button below.
forever
show leds
show leds
show leds
This shows that you don't need to use that many LEDs to produce an animation.
Have a different image appear on your Micro:Bit when button A is pressed.
Tip: Button A is an input so look for the menu that will have the block you need.
Tip: To test the program, button A does not mean the A button on your keyboard. It means the A button on the Micro:Bit inside the simulator which can be clicked on with your mouse cursor.
The block you will need is in the Input block menu.
This block does not go inside the 'on start' or 'forever' blocks. Instead, it starts a new section of code blocks.
If you are still stuck, use the answer button below.
on button A ⯆ pressed
show icon
⯆
Add sound or music to your start-up sequence.
Tip: Check your computer volume is low before adding sound. You can adjust it during testing to a level of your choosing.
Tip: If using music, keep the tune short and only play once, or you'll have a long wait for this to complete during each test.
Tip: If you don't want to create your own tune, scroll down the Music menu to find ready-made melodies and sounds.
If using the 'play melody' block from the top of the Music menu, you can create your own tune by clicking on the musical note symbol in the block, then highlight the boxes to produce different notes.
If using the 'play melody' block with preset tunes, change the 'in background' option to 'until done' using the drop-down arrow.
If you are still stuck, use the answer button below.
Using your own tune:
on start
show leds
play melody ♫ at tempo 120 (bpm)until done ⯆
Using preset melody:
on start
show leds
play melody funk ⯆until done ⯆
Using sound effect:
on start
show leds
play happy ⯆until done ⯆
Have the Micro:Bit react when it hears a loud sound.
Tip: If you remember from the video, the microphone acts as a sound sensor and is an input device.
Tip: You could use an image, text, music, or sound as the reaction.
Tip: A loud sound in this program is any value over 170.
The block you need is in the Input blocks menu.
Look under micro:bit (V2). It is in this section because there are now two versions of the BBC Micro:Bit and only version 2 has a microphone.
You will need to re-watch the video if you are unsure how to create a loud sound in the simulator.
If you are still stuck, use the answer button below.
This solution has the Micro:Bit show a message when it hears a loud sound.
on loud ⯆ sound
show string " SHHH! "
Inside the same program, create the following:
At the end of your start-up sequence clear the screen and add a welcome message.
Tip: Keep the message short as you'll have to wait for it to complete every time you test your program.
Tip: Both blocks needed for this are in the Basic menu.
In programming we use the word string to describe any series of symbols.
You will need to find the 'show string' block and then you can change the word "hello" to a word/message of your choosing.
If you are still stuck, use the answer button below.
on start
show leds
play happy ⯆until done ⯆
clear screen
show string " Hi "
Add a message into your forever loop that says 'Need Input'.
Tip: Think of this as a waiting screen.
You will use the same block as we used for the welcome message above.
If you are still stuck, use the answer button below.
forever
show leds
show leds
show leds
show string " Need Input "
Have the Micro:Bit display different images for when the B button is pressed and when both buttons are pressed.
Tip: The 'on button A pressed' block has a drop-down arrow on it that allows you to change the A to B or A+B.
Remember that the button blocks can be found in the Input menu.
You will need three of these blocks in your program, one for each button combination.
To test this, the simulator should now have a new button labelled A+B, this allows you to mimic the effect of pressing both buttons using the mouse.
If you are still stuck, use the answer button below.
on button B ⯆ pressed
show icon
⯆
on button A+B ⯆ pressed
show icon
⯆
Add different sound effects depending on which button is pressed.
Tip: You may start to see some unwanted behaviours in your tests as we add more blocks to the button programs. We shall cover why and how to avoid this later in the series.
If uncertain, refer to step 4 in the bronze challenge.
If you are still stuck, use the answer button below.
on button A ⯆ pressed
show icon
⯆
play giggle ⯆until done ⯆
on button B ⯆ pressed
show icon
⯆
play mysterious ⯆until done ⯆
on button A+B ⯆ pressed
show icon
⯆
play soaring ⯆until done ⯆
Add a reaction for when the Micro:Bit detects it is quiet.
Tip: A lot of blocks include drop down menus that allow you to change key words.
Tip: For the Micro:Bit, quiet is any noise level below 90.
Remember that sound detection is an input.
The 'on loud sound' block can be changed.
A reaction could be a sound, image, icon, or message.
If you are still stuck, use the answer button below.
on quiet ⯆ sound
show leds
Continue building your program by adding the following:
Replace the image on start-up with an animation.
Tip: You could use repeating images, or you may want to use a block from the Loops menu to help with this.
There is a 'repeat 4 times' block in the Loops menu that can be set to any number of repeats. This means you only need to use each image once.
If you are still stuck, use the answer button below.
on start
repeat 4 times
show icon
⯆
show icon
⯆
play happy ⯆until done ⯆
clear screen
show string " Hi "
This program's start-up animation is a beating heart.
Change your forever loop animation to show a person or animal moving onto the screen.
Tip: Choose or create a full image of your person/animal first. Then you can create the animation more easily.
Have your animal/person appear from the left of your screen one column of lights at a time and then move them all the way across the screen.
If you are still stuck, use the answer button below.
forever
show leds
show leds
show leds
show string " Need Input "
Have the Micro:Bit react differently when tilted left and when tilted right.
Tip: Some blocks have drop down menus to change a key word.
Tip: The Micro:Bit is using its accelerometer for this which is a movement sensor. Is this an input or an output?
You will need to use a block from the Input menu.
Is there a movement-based block you can use? What options does it have for the key word?
If you are still stuck, use the answer button below.
on tilt left ⯆
show leds
on tilt right ⯆
show leds
Add sound effects to being tilted left and right.
This is the same as when we added sound effects to the button inputs.
If you are still stuck, use the answer button below.
on tilt left ⯆
show leds
play slide ⯆until done ⯆
on tilt right ⯆
show leds
play twinkle ⯆until done ⯆
At the end of your forever loop replace the 'show string Need Input' block with a clear screen block and then show the value of the sound level instead.
Tip: The sound level on a Micro:Bit is measured as a number.
Tip: You will need to merge two blocks together to make this instruction.
There is a 'show number' block in the Basic menu.
The sound sensor is an input device, so you will need to look in the Input menu for the block that will fit inside your 'show number' block.
If you are still stuck, use the answer button below.
forever
show leds
show leds
show leds
clear screen
show number Sound Level
Video Lesson:
Exercises:
For this session we shall be creating a program to turn your BBC Micro:Bit into a virtual pet.
As with all our exercises, they are designed for learners to complete a level before moving to the next. Otherwise, you may miss information or skip a crucial step that stops your program from working.
Click on each challenge heading to expand.
Start a new Micro:Bit program on Makecode and work your way through the following stages.
Have a message and/or image appear on start to help identify the program.
Tip: Remember that the clear screen block can be used to create a break between an image and a message.
Create a little animation of your pet waiting inside the forever loop.
Tip: You may be able to use one you created in Session One.
Remember, you only need two images to make an animation.
You can use the pre-made icons to get you started.
The more images you use, the longer the forever loop will take to complete - this could cause problems as we build the program.
If you are still stuck, use the answer button below.
Use one of the inputs (like button A) to feed your pet - have it show an image of a food item on the screen.
You may need to clear the screen before showing your food image.
Remember, the button A control block is in the Input menu.
If you are still stuck, use the answer button below.
This answer includes my attempt at drawing a burger for my pet.
Have an animation to show the pet eating.
Important: You may start to see some unwanted behaviours with your animations clashing. By using our new if statement blocks, we can correct the issue and have the whole program stored inside a single forever loop. The below image shows how to include button A as a condition in an if statement inside the forever loop.
Please note: The longer your forever loop, the more time it will take for the program to react to an input. You may need to hold down the inputs for longer to register.
Remember: You should only have one forever loop in your program.
Tip: Use the else section on this if statement block as a new home for your pet waiting animation.
You can animate either the pet or the food for this effect.
A repeat block from the Loops menu will help with the animation.
If you are still stuck, use the answer button below.
Have your pet react badly (you can use an image, animation, and/or sound) when it hears a loud noise.
Tip: Instead of using the 'on loud sound' block, use an else if statement inside your forever loop for when the sound level is > 175.
You can expand an if statement by clicking on the plus sign. You can do this for as many else ifs as you need.
You can find the greater than comparison block in the Logic menu.
To test your program, use the new microphone volume bar on your simulated Micro:Bit to adjust the value. When you go above 175 you should see the program - there might be a slight delay.
If you are still stuck, use the answer button below.
Continuing with the same program, continue with the below additions.
Have your pet fall asleep when it gets dark (use less than or equal to 70 for this value).
Tip: You can have as many else if statements as you need in a Micro:Bit program.
Use the plus button at the bottom of your if statement to add another else if statement to your program.
Check which symbol you are using for the comparison. It should look like ≤.
You could just use a string of 'zzz' to indicate your pet has fallen to sleep.
Don't forget to clear the screen first.
If you are still stuck, use the answer button below.
Create a variable for 'fullness' which goes up by one every time your pet is fed.
Tip: It is always good practise to set a new variable to zero on start.
There is a change variable by 1 block which does what we need.
Which section of the code does it need to go into?
Make sure you do not put it inside an animation's repeat loop.
If you are still stuck, use the answer button below.
Use an input (perhaps button B) which will show the user the value of 'fullness'.
You can put a variable inside a show string block.
If you are still stuck, use the answer button below.
Have your pet react happily to bright light (use greater than 200 for this value).
If you've chosen to do an animation, don't forget about the repeat block in the Loops menu.
Check your comparison symbol is >.
If you are still stuck, use the answer button below.
I chose to have my snake celebrate bright light with a somersault animation.
Have your pet make a noise to get attention if the sound level is less than or equal to 50.
Tip: Have a pause block (at least 500 milliseconds) after your sound has played - trust me.
Make sure that whatever noise you've chosen to use in the program only plays until done or once.
If you are still stuck, use the answer button below.
Now, let us build up the program further with the following tasks.
If your pet is asleep when it hears a loud sound, it must react more angrily/scared/surprised than when it is awake.
Tip: You can put if statements inside each other, making a stacked if statement.
Important: Your program will work its way down the list of if and else if statements in the forever loop, it will run the first bit of code where the conditions are met, and skip the rest.
Think of it like a check list where once something has been checked you return to the top of the list and start again.
This means that you need to check which of the conditions (loud sound or darkness) comes first in your program and insert the new if statement into that one.
Use an if and else statement for this to determine which loud sound reaction is shown.
As we want to clear the screen before both options, we can just use this command once before the new if/else statement.
Alternatively, you could look at using advanced logic blocks that allow multiple conditions in an if/else if statement.
If you are still stuck, use the answer button below.
In our answer program, the loud sound condition is above the dark condition, so the new if statement goes there.
Your 'fullness' variable needs to have a maximum value of 5.
Tip: This means you only want to add one to the fullness value when it is less than 5 (or less than and equal to 4).
You need an if statement for when the fullness is less than 5 to only add to the value when true.
Currently, this does not require an else statement as there is no action for when the if statement is not true.
Remember to keep this if statement outside of any repeat loops used for the feeding animation.
If you are still stuck, use the answer button below.
Instead of showing the user the value of fullness using the input chosen in the silver challenges, have it show a meter level.
Tip: You can also put else if statements inside another if / else if / else statement.
This will require an image for each fullness level to create the effect of a meter/gauge.
In this sort of statement list, you want to include an else statement to capture the 0 and/or any unexpected values. This then can act as an error screen for us.
If you are still stuck, use the answer button below.
We went for a round meter shape that gets more complete the higher the fullness level.
The pet should refuse to eat if it is full (fullness = 5).
Tip: It might help to move the eating animation into the same if statement as when the fullness variable increases, then you can have a different animation for when full in an else statement.
Remember that repeat loops are required inside these statements for repeating animations.
When building up a program we often have to re-shuffle the locations of code sections to include new features.
This requires an else attached to our if fullness < 5 statement.
If you are still stuck, use the answer button below.
The fullness value should slowly drop down over time as your pet starts to get hungry again.
Tip: As this is a background process that will not suffer interference from the forever loop, you can use a separate timer loop to do this.
You can find a timer block in the Loops menu.
The default time is 500 ms - this is every half a second - you will need to change this (we found a minute - or 60000 ms - to work well for this).
We want to take one away from the fullness so we can use the change fullness by block with a -1 instead of 1.
We don't want negative values, so we only want to take away from the fullness value if it's over 0 (or greater than and equal to 1).
If you are still stuck, use the answer button below.
You now have a virtual pet. Here are some ideas of further additions and features you may want to have a go at adding. These are for you to investigate and explore - there are no answers provided.
Having the pet show when it is very hungry (fullness ≤ 1).
Tip: This can be done by adding another else if statement to your forever loop.
Adding a happiness level and play inputs into the program. The more you play with the pet, the happier it is.
Tip: You may want to move the hunger meter to show automatically after feeding to free up button B for this.
Setting a maximum value and a cool-down time for the happiness value. How will your pet react when the happiness value drops too low?
Tip: This will use the same framework as our fullness meter.
Have the pet grow over time if it is looked after correctly.
Tip: You could create a score variable for this and have the pet improve as the score reaches certain goals.
Video Lesson:
Exercises:
For this session we shall be creating a two-player dice duelling game using two BBC Micro:Bits. We recommend using the multi-editor for these exercises. Name the program on the left Player One and the other Player Two.
As with all our exercises, they are designed for learners to complete a level before moving to the next. Otherwise, you may miss information or skip a crucial step that stops your program from working.
Click on each challenge heading to expand.
Have both Micro:Bits programmed to show a random number between 1 and 6 every time it is shaken - like a dice roll.
Tip: To avoid interference between loops, all outputs need to be inside the forever loop.
The video for Session Two included a walk-through on creating a basic dice program.
Use a different dice roll variable name for each player - this will reduce confusion later.
You only want the dice roll value to start showing after the first roll (so when the variable is no longer 0)
Player One
Player Two
For Player One, have button A show your last roll whilst button B shows the other player's last roll. Do the same for Player Two.
Tip: Don't forget to set both Micro:Bits into the same radio group so they can talk to each other - this should be done during the start-up sequence.
Use if statements inside the forever loop for button pressing, not the separate 'on button A pressed' or ' on button B pressed' blocks.
Remember, you can stack if statements inside each other.
You can have an else statement that contains nothing, or you can use it to report an error.
Player One
Player Two
When either player presses the touch logo, have the screen show the signal strength.
The touch logo is only available on Micro:Bit V2 - so check the V2 section of the input menu.
This one is hard to test in the simulator because you can only alter the signal strength when it is sending information (in this case when we shake it).
Player One
Player Two
Pressing button A and B at the same time should give players the total of both players dice rolls.
Tip: You will need to have something to check both players have rolled.
Important: To check against two conditions (in this case, that both players have rolled), you could stack the if statements or you could use an 'and' block.
Stacked Conditions
The 'and' Boolean Operator
Note: A Boolean value is true of false. A Boolean Operator compares two inputs to produce a single true or false output.
Tip: The if button A and B pressed statement needs to be put in the forever loop above the if statements for button A and button B.
Important: When using else if statements, the program goes down the list of conditions and stops at the first one that is true. It will then skip the rest. When using the if button A and B pressed, any conditions checking if either of those buttons is pressed becomes true. So, 'if button A is pressed' will be true, 'if button B is pressed' will be true and 'if button A+B is pressed' will be true. This highlights the importance of the ordering of conditions.
There are blocks that do the calculations for us in the Maths menu.
You may want to add an else statement to this to show that not all players have rolled yet.
Move the program for button A so as the Micro:Bit will show the roll on the screen automatically, include an else statement for when the dice roll value is zero. This could be a waiting animation, image, or message/instruction.
Tip: Now you will need pauses to keep values other than the player's own roll on the screen longer.
You can move the show player's own roll program into the else statement for this.
Use 1 second (1000ms) pauses where needed.
You may need to hold down buttons for slightly longer when testing. Especially if you are using a string to show a message as it will not listen for buttons until the message has finished scrolling.
Leave the 'else if button A is pressed then' statement empty for now.
Player One
Player Two
Now use Button A to reset the game.
Tip: You will need to also send the reset command to the other player's Micro:Bit.
You can send a string, such as a word, over the radio group.
If using a string for this, you need to use the string comparison block - this is the one with quotation marks inside the value boxes.
Alternatively, you could send a different number which triggers the reset.
Check you are using the correct receiving blocks for the type of information you are sending.
Player One
Player Two
Let us now have the players duelling. Whichever player rolls the highest number wins. Have the Micro:Bits show whether their player won or lost.
Tip: You can use the 'and' Boolean operator here to make sure both players have rolled before checking to see who won.
You need to work out where to put this in your program.
Compare the two players dice rolls to work out which is higher.
What happens when the players both roll the same number?
You can use images, strings, and/or animations for these.
Add pauses where you think they are needed.
Player One
Player Two
Upgrade the program so both players must roll twice before comparing their totals to determine the winner. Players should not be able to roll more than twice reset.
Tip: You will need a new variable for the number of dice rolls.
Your new counter variable will need to be used in place of all conditions that currently check if the player's own roll value is over 0.
Have a message or image come up if a player tries to roll more than twice - this makes it easier to test.
The use and changing of the counter variable can be done in the 'on shake' loop.
You will need to set this new variable to zero both on start and during the reset process.
Changing the random number to be between 1 and 12 or multiplying the initial roll by two will not match the same probabilities as using two separate dice rolls - therefore, you will need to use a roll counting variable. For more information regarding probabilities of dice rolls, you can check out our Dice Duelling activity.
Player One
Player Two
Here are some extra features you can add to your dice duelling game. These are for you to investigate and explore - there are no answers provided.
Adding instructions to player screens.
Tip: Try to keep instructions short or in picture form.
Have a score system that tracks how many times each player has won or lost.
Tip: You can replace the programs for a button or use the touch sensor.
Let the players know if they are shaking the Micro:Bit too hard.
Tip: This requires measuring the acceleration of the Micro:Bit, anything over a strength value of 1700mg is too much.
Add animations to the dice rolls.
Can you design a version of this game for two players using only one BBC Micro:Bit?
Tip: This will not need any radio communications.
Video Lesson:
Exercises:
For this session we shall be creating a traffic light program using a Neopixel strip.
As with all our exercises, they are designed for learners to complete a level before moving to the next. Otherwise you may miss information or skip a crucial step that stops your program from working.
Click on each challenge heading to expand.
Use the blocks provided by the Neopixel extension to connect a 24 LED strip to pin 1.
Tip: Don't forget to create your own start-up for this new program to identify it.
This is part of the set-up for your program, so should be done in the 'on start' block.
Set up 3 equal size ranges to recreate a traffic light with red at the top, yellow in the middle, and green at the bottom.
Tip: The LED strip numbering starts at 0.
24 is dividable by 3, meaning you'll need to have the ranges cover 8 LEDs each.
Have the traffic light repeatedly cycle through a crossing sequence - that is red for 10 seconds, red and yellow for 5 seconds, green for 10 seconds, and then yellow for 5 seconds.
Putting this sequence in the 'forever' loop will ensure it repeats continuously.
Remember to turn off the un-needed colours each time (set them to black).
Move each light change into their own functions, remember to then call them in the forever loop.
Give each function a suitable name.
Add animations to the Micro:Bit to show when it is and isn't safe for pedestrians to cross the road. Do this using three new functions - one for walk, one for wait, and one for warning that the lights are changing to green for the traffic.
Tip: You will need to time your animation to replace the use of pause blocks currently for timing the lights.
Tip: A variable will mean you only need one function for wait that can be used for when the light is green and when it's yellow.
This is a good opportunity to practice working with the 'repeat' blocks inside the functions.
You can call a function from inside another function.
If using two images for your animations, you'll need to repeat them 10 times with half seconds pauses after each for the red and green. Only 5 repeats when the yellow light is active.
Create a traffic light colour variable for use to identify which light is currently active and use this in if/else if statements for setting the lights.
Tip: Remember to set the variable in the 'on start' block.
You will need to use numbers to represent the different light states.
Use an else statement to capture any errors regarding the variable value.
Have the A button on the Micro:Bit cause the traffic to come to a stop.
Tip: You only need this over-ride to work whilst the traffic lights are green.
Important: You can stop a loop early using the 'break' block found in the Loops menu.
You need to tell the program to change to yellow when button A is pressed.
To over-ride the program in this way, you will need to check if button A is pressed inside the relevant animation's repeat block.
You may also need to check against another variable, this can use a stacked if statement or an 'and' Boolean Operator.
Add sound to indicate when it is safe to cross for those who cannot see the visual instructions.
This just requires a single note to be played on each image change in the animation for when it is safe to start crossing (when the traffic light is red).
The below exercise is to expand the program further. This is for you to investigate and explore - there are no answers provided.
Add a second Neopixel to pin 2 and have it act as the traffic light for traffic flowing in the other direction.
How much can you tidy up your code with functions, while loops, repeat blocks, and variables?
Video Lesson:
Exercises:
For this session we shall be creating a program to turn your BBC Micro:Bit into a sound meter using a servo.
As with all our exercises, they are designed for learners to complete a level before moving to the next. Otherwise you may miss information or skip a crucial step that stops your program from working.
Click on each challenge heading to expand.
Write a program that plays an alarm when the sound level is over 200.
Tip: Don't forget the start-up routine to identify the program.
This requires an if statement with a condition of sound level > 200.
There is a variable block for the sound level in the Input menu for the V2.
Add some pauses to reduce the rate of your chosen sound/note.
Have the Micro:Bit display the sound level on its screen.
Tip: This can be done using a 'show string' block.
This needs to be in the forever loop, outside of the current if statement.
Notice how the show string block slows down our alarm sound. Let us resolve this by replacing the number with these images and conditions:
Sound level is 0.
Sound level is over 0 and less than or equal to 51.
Sound level is over 51 and less than or equal to 102.
Sound level is over 102 and less than or equal to 153.
Sound level is over 153 and less than or equal to 204.
Sound level is over 204.
The alarm should now only sound when the meter is full.
This will require a new series of if and else if statements.
Remember you can use the 'and' Boolean operator instead of stacking if statements.
Use the else statement at the end for any errors in the program.
Add a 180° positional servo to pin 1. Program the servo to rest at 0° whilst the sound level is less than or equal to 102. Otherwise, it needs to move to 180°
Tip: You will need to use the servo extension.
We can use all the default settings for the positional servo for this. However, it is still good practice to set the servo to a start position (0° in this case) in the 'on start' block.
You will need to set the servo angle in each if/else if statement.
When testing, make sure you give the servo time to complete its rotation - if you switch the condition too quickly it will not behave the way we expect it to.
When the servo changes direction, can you have the servo move only 10° every 300 milliseconds? This reduces the stress on the servo, stopping it from breaking - something the simulator does not replicate.
Tip: You will need to make sure the servo does not attempt to turn below 0° or further than 180° - this could break your servo.
You will need to create a variable for the angle - remember to set this in the 'on start' block.
This new variable can be used to set the servo angle - changing it up or down by 10°.
When setting up your if statement conditions consider the values to use - as we're moving 10° at a time, consider using 10 and 170.
These new if statements will need to replace the set servo blocks in each if/else if statement.
As there is already a 200 millisecond pause in the > 204 statement, we need to adjust the movement to total 300.
To tidy up our code, let's move the servo instructions into their own functions and call them when needed.
Tip: You'll need one for lowering and one for increasing the angle.
Remember the Functions menu is in the Advanced section.
To only have two functions - remove the 200 millisecond second pause from the alarm program so it too can use the 300 milliseconds pause in the servo function.
Before you start this exercise, we advise that you duplicate your program as we will be deleting a lot of the previous code.
Step 1. Close your program and return to makecode.microbit.org's homepage.
Step 2. Click on the view all option next to 'My Projects'.
Step 3. Select the file you want to duplicate (a green tick should appear on the file).
Step 4. Click on the duplicate option in the top right of the screen. This will allow you to then select a name for your new copy.
Step 5. Open your new copy and continue with the next challenge.
Instead of having a single value determining the movement of the servo, let us look at having the servo act like the arm on a sound meter (as shown below), traveling to the correct angle for the current sound level.
Important: We have a range of 0° to 180° on the servo but the sound level has a range of 0 to 255. There are two ways to approach this:
Do the maths ourselves
Work out how far the meter needs to move for one unit of sound:
(180 ÷ 255) = 0.7058823529411°
Use the above value with a Maths block inside a 'set servo' block.
Use the 'map' block
The map block allows us to enter the range we're measuring (sound level) which is 0 to 255 and convert it to the servo's range of 0 to 180. The block then does all the calculations for us.
We need to delete the functions we've created for the servo from our program. The 'call' blocks will automatically vanish when their function is removed.
Keep the screen meter animation in place.
A single 'set servo' block using the method chosen from above is all that's required for this.
The below exercises are designed to expand your understanding of servos. These are for you to investigate and explore - there are no answers provided.
Instead of using the meter to measure sound level, have it measure radio signal strength, with an alarm for if the signal gets too weak.
Tip: You will need to find the range of values for the radio signal strength.
Remember the traffic light program we created last session? Now you can add a rail crossing with a servo acting as the barrier arm.
Tip: You can only attach the servo to pins 0, 1 or 2. However, you can relocate the Neopixels to other pin numbers (up to 16).
Video Lesson:
Exercises:
For this session we shall be creating a program to control a railway crossing. This includes revision of radio communications, if-statements, variables, functions, Neopixels, and servos.
We recommend you attempt these challenges using the standard editor.
As with all our exercises, they are designed for learners to complete a level before moving to the next. Otherwise, you may miss information or skip a crucial step that stops your program from working.
Click on each challenge heading to expand.
For these exercises, imagine you have one Micro:Bit controlling the crossing whilst another is acting as a beacon on-board the train. The crossing will know a train is coming when the beacon's signal strength gets stronger.
Use an image, animation and/or text to create a start-up screen that identifies your program.
If only using an image, include a pause (500ms) so it remains on the screen long enough to see.
Try not to make the start-up take too long, otherwise this will get frustrating during testing as we progress.
Have the Micro:Bit send the number zero via radio from inside the forever loop.
Tip: Don't forget to set a radio group for your Micro:Bit to use.
You can find the blocks you need in the Radio menu.
You need to set a radio group in the start-up sequence.
Create a beacon strength variable and have it set to the signal strength being received.
Tip: To measure the signal strength, the program needs to first receive the sent number.
Pick a suitable name for your new variable. Some programs use lots of variables, and it helps to be able to quickly identify what each one is for.
Remember to set your new variable to 0 when the program first starts - This is good practice for when you start learning text-based programming languages.
You will need to set your new variable to the received signal strength value inside an 'on radio received' block.
We now need two functions, one for the program for when a train is coming, the other for when there isn't. Give each function a suitable name and have a different image in each.
Tip: The images at this stage are for testing, so any will do.
The Functions menu can be found in the Advanced section.
These functions will not show in testing, as we have not called them in the program.
Call your function for when a train is coming when the signal strength is greater than or equal to -75. Otherwise, call the no train coming function.
Tip: While testing in the simulator, treat the top Micro:Bit as the crossing controller and the bottom Micro:Bit as the train beacon.
You will need to create an if statement for this which compares the beacon strength value to -75.
The radio signal strength for the Micro:Bit in the simulator has a range of -128 (weakest signal) to -42 (strongest signal).
Remember we have several maths symbols to choose from: = equals, < less than, > greater than, ≤ less than or equal to, and ≥ greater than or equal to.
We now need to create our crossing lights. For this we need a Neopixel connected to pin 1 which is made up of 15 LEDs.
Tip: You'll need to add the Neopixel extension to your blocks menu.
Re-visit Session Four if you need a reminder of how to get and use the Neopixel extension blocks.
You will need to change the default length from 24 to 15 LEDs.
Set up two ranges, with suitable names - one for the top 5 LEDs and another for the bottom 5 LEDs.
Tip: Remember that counting in computing starts at zero.
The first range will start at 0, whilst the bottom range will start at 10.
Remove the image in your function for when a train is coming and replace it with a program that will turn the lights on and off (alternating between the top and the bottom) three times. Include a pause of 500ms after each light turns on.
Tip: Remember that setting a light to black turns it off.
Each time a light turns on, the other needs to turn off.
You can use a 'repeat 3 times' block to shorten the program.
Replace the image in you function for when a train is not approaching with a program to make sure the lights are all turned off.
You will need to set both of our light ranges to black in the function for when there is no train coming.
Have your program play a middle C note when the top light is on and a middle E note when the bottom light is on. This is our alarm to warn drivers and pedestrians a train is coming.
Tip: When testing, make sure the top Micro:Bit (our 'crossing') has a very low signal strength or the alarms on both Micro:Bits may merge and/or be out of sync.
You only want the notes to be 1 beat long.
You can change the note inside the 'play tone' block.
For our railway crossing barrier we shall use a servo to control its movement. This needs to be connected to pin 2 and be in the open position (0°) at the start of the program.
Tip: This will require the Servos extension.
If stuck, please look back at Session Five.
When a train is approaching, we want the lights and alarm to sound three times and then for the barrier to close (move to 90°).
Be careful not to place this new instruction inside the repeat loop.
Remember that the servo is on pin 2.
Once the barrier is closed, we need the alarm to stop while the lights continue to flash.
Tip: You will need a way to check the angle of the servo.
You will need a servo angle variable.
This new variable will need to be updated each time the barrier opens or closes.
Move the program with the lights and alarm into an if statement for when the barrier is open.
For when the barrier is closed, have the lights continue to flash. As long as the barrier is down, this will keep repeating, so you don't need to use a repeat block here.
Once the train has passed and the beacon signal fades to less than 75 again, we want the barrier to open (retuning to 0°).
Tip: Remember to also reset your new angle variable at the same time.
You can use the angle variable to tell if the gate needs opening. This is the opposite to the check we've already done to see if it needs closing.
Don't forget that our servo is attached to pin 2.
At the moment, the servo is moving too fast. This could cause injury to a pedestrian or damage a passing vehicle. So we need the barrier to lower 5° every 200ms. When it is opening, it is safer to go faster - in this case 20° every 300ms.
Tip: Turn both the red lights on fully during these movements as the flashing will stop during these movements.
Our function for when our train is coming will need an else if statement for when the barrier is only partially closed.
You will need to use the angle variable in the maths conditions.
Remember you can also use the 'and' Boolean block demonstrated previously if you want to check against two values.
Perhaps create new functions for the opening and closing movements. Yes, you can call a function inside another function.
When opening the barrier be aware that 90 cannot be divided by 20. Think about how you will make sure the barrier opens fully without going too far and breaking the servo.
This section is an additional activity for you to try out - this will provide an opportunity for revision whilst introducing some new blocks and terms.
As with all our exercises, it is best to work through this is order.
Select a heading to expand.
Create a basic dice rolling program on your Micro:Bit. This should show a random number between 1 and 6 on the screen when shaken.
Tip: Don't forget your start up screen.
If stuck, revisit sessions two and three.
This does not require a forever loop.
Instead of showing a number, have the screen show the following images depending on the value rolled.
One
Two
Three
Four
Five
Six
Tip: You will need to create a variable to hold the dice roll value.
You will need a different if/else if statement for each possible value. You can then use the else statement to catch any errors.
A Magic-8 Ball is like a dice, put instead of numbers it produces answers when shaken.
Instead of showing numbers in your program, have the Micro:Bit display the answers yes, no, maybe, go for it, good idea, bad idea, don't know, definitely, absolutely not, and no idea.
Tip: There are now 10 options.
For the first six options you can simply replace the current images.
You will then need to add four more else if statements.
Don't forget to change the random number generator to have 10 options instead of 6.
There is a different way we could have approached this program. We could have used something called an array. Array blocks can be found in the Advanced menu.
An array is a special kind of variable. Instead of holding only a single piece of information like the variables we've used, it can hold a list of values/strings.
You can then call a value from the array by its location in the list. As with most coding, the numbering of list items starts at zero.
Example:
Let's say we wanted to write a program that randomly selected a string from a list of apple, orange, and banana when we press button A.
As with any variable, we need to set the array in the 'on start' section:
We can add or take away items to the array using the plus and minus buttons on the block.
To have the screen show a random item from the array we can use the 'show string' combined with a 'get random value from' array block.
We now have a complete program that randomly selects an item from the list and displays it on the screen when we press button A.
As the Magic-8 Ball program has a single variable which has a list of different strings (the answers) we could use an array and have the program randomly select from a list instead of using such a large if/else if/else statement.
Important: Arrays cannot be used to replace all if and else if statements. With Makecode, they can only be used for lists of strings or numbers. For example, you could not use this for the dice program with different images for each value.
Change your Magic-8 Ball program to use an array for all possible answers and randomly select from it when shaken.
Tip: You may want to duplicate your file first so you can compare them later.
Use the fruit list program in the example and replace the fruit with the Magic-8 Ball answers provided in the silver exercise.
Make sure you are using the text list block, the number version will error if you add words.
Remember, you can add more items to the array using the plus symbol on the set-up block.
Rename the list to something more suitable than fruit.
If you haven't already, re-design the start sequence for the Magic-8 Ball instead of the dice.
Now that you've discovered random generators using arrays, there are number of different fun things you can create. Here are some ideas.
A volunteer selector - you can create an array containing all the names of people in your class and next time no one volunteers, you can use it to select someone randomly.
Creative writing program - have a series of arrays to help put together a storyline idea. For example, you could have random location/genre/character/sidekick generators.
Shopping mayhem app - put your shopping list into an array and then use the random generator to decide what order to shop in.
Tip: You may want to do some research on how to remove items from an array after they've come up.