制造商零件编号 2012414
MICRO:BIT V2 SBC-BOARD ONLY
OKdo
所订产品一般在 7-10个工作日 内送达中国,具体时间取决于收货地点。
最低订购金额为人民币 300 元,顺丰快递免运费配送。
当用人民币下单时,按照国际贸易条款 DDP(DigiKey 支付关税、海关费用和当地税款)方式结算。
电汇预付
更多来自全授权合作伙伴的产品
下单后,从合作伙伴发货平均需要时间 1-3 天,也可能产生额外运费。可能另外收取运费。 实际发货时间请留意产品详情页、购物车和结账页面上的说明。
国际贸易结算方式:CPT(交货时支付关税、海关费用和适用 VAT/应付税金)
有关详情,请访问帮助和支持
License: See Original Project micro:bit
Courtesy of Kitronik
Guide by Kitronik Maker
In this blog we are going to look at how we can multitask on the BBC micro:bit with MakeCode. In our example we used the Kitronik HaloHD to visually indicate the micro:bit running two different tasks at the same time. We show the micro:bit multitasking by having the HaloHD light up in two separate pulses, going in opposite directions at different times.
Below is the embedded MakeCode project we used for the HaloHD example. Next, we’ll step through how the multitasking parts of this project piece together.
Microsoft MakeCode | Terms of Use | Privacy | Download
Inside the on start block we want to setup a flag variable called runA which we’ll set to false. The runA variable is used to tell the micro:bit when to start executing our two tasks.
Next, we setup the on button A pressed block to trigger our tasks to run by setting runA to true.
Then, we have our two forever loops which are used to run our two tasks. In each forever loop our task sits inside of an if runA then block. This means that when the runA variable is set to true the code inside the block will be executed. In the first task, we have the micro:bit pause for 1 second before it starts running the code in this task. In the second task, we have the micro:bit pause for 2.5 seconds before it starts running the code in this task. The different delays between the two tasks can be seen in the example as the blue side of the HaloHD begins to fill after the red side is already half full.
To allow for proper multitasking on the micro:bit, it is important that there are some delays inside of the task. This is done in the example by having the tasks pause for 50 to 100 milliseconds in between updating an LED. By having a pause block inside the task, we allow the micro:bit to swap over to the other task temporarily and continue executing the code inside of there.
Finally, at the end of each task we want to set the runA variable to false, to stop the tasks from being run again the next time the forever loop repeats itself.
©Kitronik Ltd – You may print this page & link to it but must not copy the page or part thereof without Kitronik's prior written consent.
谢谢!
敬请关注收件箱中的 DigiKey 新闻与更新!
请输入电子邮件地址