|
|
Riadok 92: |
Riadok 92: |
| # [[Visačka na diskotéku]] | | # [[Visačka na diskotéku]] |
| # [[Počítadlo návštevníkov]] | | # [[Počítadlo návštevníkov]] |
| | | # [[Kuchynské minútky]] |
| <!-- **************************************************************************** -->
| |
| | | |
| <!-- **************************************************************************** --> | | <!-- **************************************************************************** --> |
|
| |
| <gallery heights=200px mode="packed"> <!-- slideshow? -->
| |
| Image:microbit-PeopleCounter.png|''Prvý program...''
| |
| Image:microbit-PeopleCounterRun.png|''...bude vyzerať v simulátore takto.''
| |
| </gallery>
| |
|
| |
| Pocitadlo ludi pri vchode:
| |
|
| |
| <tabs>
| |
| <tab name="Javascript"><source lang="javascript">
| |
|
| |
| input.onButtonPressed(Button.A, function () {
| |
| pocetNavstevnikov += 1
| |
| })
| |
| input.onButtonPressed(Button.AB, function () {
| |
| pocetNavstevnikov = 0
| |
| })
| |
| let pocetNavstevnikov = 0
| |
| pocetNavstevnikov = 0
| |
| basic.showIcon(IconNames.Yes)
| |
| basic.forever(function () {
| |
| basic.showNumber(pocetNavstevnikov)
| |
| })
| |
|
| |
|
| |
| </source></tab>
| |
| <tab name="Python"><source lang="python" style="background: LightBlue;">
| |
|
| |
| # MindPlus
| |
| # microbit
| |
| from microbit import *
| |
|
| |
|
| |
| mind_n_pocetNavstevnikov = 0
| |
|
| |
| def on_button_a():
| |
| while True:
| |
| if button_a.is_pressed():
| |
| yield callback_button_a()
| |
| else:
| |
| yield
| |
|
| |
| # Event callback function
| |
| def callback_button_a():
| |
| global mind_n_myValue, mind_n_pocetNavstevnikov, mind_s_my_string_variable
| |
| mind_n_pocetNavstevnikov = mind_n_pocetNavstevnikov + 1;
| |
| def callback_button_a():
| |
| global mind_n_myValue, mind_n_pocetNavstevnikov, mind_s_my_string_variable
| |
| mind_n_pocetNavstevnikov = 0
| |
|
| |
|
| |
| func_button_a = on_button_a()
| |
| mind_n_pocetNavstevnikov = 0
| |
| while True:
| |
| next(func_button_a)
| |
| # 滚动显示字符串,不支持中文字符
| |
| display.scroll(str((str(mind_n_pocetNavstevnikov))), wait=False, loop=False)
| |
|
| |
|
| |
| </source></tab>
| |
| <tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk">
| |
| /*!
| |
| * MindPlus
| |
| * microbit
| |
| *
| |
| */
| |
| #include <Microbit_Matrix.h>
| |
|
| |
| // Dynamic variables
| |
| volatile float mind_n_pocetNavstevnikov;
| |
| // Function declaration
| |
| void buttonACallback();
| |
| void buttonABCallback();
| |
|
| |
|
| |
| // Main program start
| |
| void setup() {
| |
| onEvent(ID_BUTTON_A, PRESS, buttonACallback);
| |
| onEvent(ID_BUTTON_AB, PRESS, buttonABCallback);
| |
| mind_n_pocetNavstevnikov = 0;
| |
| }
| |
| void loop() {
| |
| MMatrix.print((String(mind_n_pocetNavstevnikov)));
| |
| }
| |
|
| |
|
| |
| // Event callback function
| |
| void buttonACallback() {
| |
| mind_n_pocetNavstevnikov += 1;
| |
| }
| |
| void buttonABCallback() {
| |
| mind_n_pocetNavstevnikov = 0;
| |
| }
| |
|
| |
| </syntaxhighlight></tab>
| |
| </tabs>
| |
|
| |
|
| |
|
| |
|
| |
| <!-- **************************************************************************** -->
| |
|
| |
| [[Súbor:microbit-SimpleTimer.png]][[Súbor:microbit-SimpleTimerRun.png]]
| |
|
| |
| <gallery heights=200px mode="packed"> <!-- slideshow? -->
| |
| Image:microbit-SimpleTimer.png|''Prvý program...''
| |
| Image:microbit-SimpleTimerRun.png|''...bude vyzerať v simulátore takto.''
| |
| </gallery>
| |
|
| |
| Jednoduche kuchynske minutky
| |
|
| |
| <tabs>
| |
| <tab name="Javascript"><source lang="javascript">
| |
| input.onButtonPressed(Button.A, function () {
| |
| for (let index = 0; index < 9; index++) {
| |
| myTime += -1
| |
| basic.showNumber(myTime)
| |
| basic.pause(1000)
| |
| }
| |
| })
| |
| input.onButtonPressed(Button.AB, function () {
| |
| myTime = 9
| |
| basic.showNumber(myTime)
| |
| })
| |
| let myTime = 0
| |
| myTime = 9
| |
| basic.showIcon(IconNames.Yes)
| |
|
| |
| </source></tab>
| |
| <tab name="Python"><source lang="python" style="background: LightBlue;">
| |
|
| |
| # MindPlus
| |
| # microbit
| |
| from microbit import *
| |
|
| |
|
| |
| mind_n_myTime = 0
| |
|
| |
| def on_button_a():
| |
| while True:
| |
| if button_a.is_pressed():
| |
| yield callback_button_a()
| |
| else:
| |
| yield
| |
|
| |
| # Event callback function
| |
| def callback_button_a():
| |
| global mind_n_myValue, mind_n_myTime, mind_s_my_string_variable
| |
| for index in range(9):
| |
| mind_n_myTime = mind_n_myTime - 1
| |
| # 滚动显示字符串,不支持中文字符
| |
| display.scroll(str((str(mind_n_myTime))), wait=False, loop=False)
| |
| sleep(1*1000)
| |
| def callback_button_a():
| |
| global mind_n_myValue, mind_n_myTime, mind_s_my_string_variable
| |
| mind_n_myTime = 9
| |
| # 滚动显示字符串,不支持中文字符
| |
| display.scroll(str((str(mind_n_myTime))), wait=False, loop=False)
| |
|
| |
|
| |
| func_button_a = on_button_a()
| |
| mind_n_myTime = 9
| |
| display.show(Image("00000:00009:00090:90900:09000"))
| |
| while True:
| |
| next(func_button_a)
| |
|
| |
|
| |
|
| |
| </source></tab>
| |
| <tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk">
| |
| /*!
| |
| * MindPlus
| |
| * microbit
| |
| *
| |
| */
| |
| #include <Microbit_Matrix.h>
| |
|
| |
| // Dynamic variables
| |
| volatile float mind_n_myTime;
| |
| // Function declaration
| |
| void buttonACallback();
| |
| void buttonABCallback();
| |
| // Static constants
| |
| const uint8_t bbcBitmap[][5] = {
| |
| {B00000,B00001,B00010,B10100,B01000}
| |
| };
| |
|
| |
|
| |
| // Main program start
| |
| void setup() {
| |
| onEvent(ID_BUTTON_A, PRESS, buttonACallback);
| |
| onEvent(ID_BUTTON_AB, PRESS, buttonABCallback);
| |
| mind_n_myTime = 9;
| |
| MMatrix.show(bbcBitmap[0]);
| |
| }
| |
| void loop() {
| |
|
| |
| }
| |
|
| |
| // Event callback function
| |
| void buttonACallback() {
| |
| for (int index = 0; index < 9; index++) {
| |
| mind_n_myTime -= 1;
| |
| MMatrix.print((String(mind_n_myTime)));
| |
| delay(1000);
| |
| yield();
| |
| }
| |
| }
| |
| void buttonABCallback() {
| |
| mind_n_myTime = 9;
| |
| MMatrix.show(bbcBitmap[0]);
| |
| }
| |
|
| |
|
| |
| </syntaxhighlight></tab>
| |
| </tabs>
| |
|
| |
|
|
| |
|
| <!-- **************************************************************************** --> | | <!-- **************************************************************************** --> |
|
| |
|
| [[Súbor:microbit-PeopleCounter.png]][[Súbor:microbit-PeopleCounterRun.png]] | | [[Súbor:microbit-XXX.png]][[Súbor:microbit-XXXRun.png]] |
|
| |
|
| <gallery heights=200px mode="packed"> <!-- slideshow? --> | | <gallery heights=200px mode="packed"> <!-- slideshow? --> |
| Image:microbit-PeopleCounter.png|''Prvý program...'' | | Image:microbit-XXX.png|''Prvý program...'' |
| Image:microbit-PeopleCounterRun.png|''...bude vyzerať v simulátore takto.'' | | Image:microbit-XXXRun.png|''...bude vyzerať v simulátore takto.'' |
| </gallery> | | </gallery> |
|
| |
|
Obsah
- Čo je to physical computing? Interaktivita v umení, priemysle, vzdelávaní.
- Zoznámte sa s BBC micro:bit - Tour de Board.
- Displej a tlačidlá
- Napájanie a konektory
- Senzory
- Komunikačné možnosti
- Začíname. Prvý program.
- Možnosti programovania: Microsoft Blocks, Javascript, Python, C++
- Vstupy a výstupy
- Displej, LED diódy
- Tlačidlá, jednoduché senzory
- Externé zariadenia
- Senzory
- Snímač tlaku
- Snímač zrýchlenia
- Kompas
- Snímač teploty
- Snímač osvetlenia
- Komunikácia
- Sériová linka a USB
- Rádio
- Bluetooth
- Vlastný projekt
Toto je zatial len priebezne robena zbierka prikladov
basic.showIcon(IconNames.Heart)
from microbit import *
display.show(Image.HEART)
#include "MicroBit.h"
MicroBit uBit;
MicroBitImage Heart("0,1,0,1,0\n
1,0,1,0,1\n
0,1,0,1,0\n
1,0,1,0,1\n
0,1,0,1,0\n"); // 5x5 image
int main()
{
uBit.init();
uBit.display.print(Heart);
release_fiber();
}
Zbierka príkladov
- Žmurkajúci smajlík
- Rozličné výpisy
- Visačka na diskotéku
- Počítadlo návštevníkov
- Kuchynské minútky
Súbor:Microbit-XXX.pngSúbor:Microbit-XXXRun.png
Prazdny
</tabs>
👉 Späť na zoznam príkladov....