Kurz micro:bit: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 52: | Riadok 52: | ||
<tabs> | <tabs> | ||
<tab name="Javascript"><source lang="javascript"> | <tab name="1: Javascript"><source lang="javascript"> | ||
basic.showIcon(IconNames.Heart) | basic.showIcon(IconNames.Heart) | ||
</source></tab> | </source></tab> | ||
<tab name="Python"><source lang="python" style="background: LightBlue;"> | <tab name="1: Python"><source lang="python" style="background: LightBlue;"> | ||
from microbit import * | from microbit import * | ||
Riadok 64: | Riadok 64: | ||
</source></tab> | </source></tab> | ||
<tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk"> | <tab name="1: C++"><syntaxhighlight lang=c style="background: Cornsilk"> | ||
#include "MicroBit.h" | #include "MicroBit.h" | ||
Riadok 85: | Riadok 85: | ||
<!-- **************************************************************************** --> | <!-- **************************************************************************** --> | ||
[[Súbor:microbit-WinkSmiley.png]][[Súbor:microbit-WinkSmileyRun.png]] | |||
<gallery heights=200px mode="packed"> <!-- slideshow? --> | <gallery heights=200px mode="packed"> <!-- slideshow? --> | ||
Riadok 94: | Riadok 96: | ||
<tabs> | <tabs> | ||
<tab name="Javascript"><source lang="javascript"> | <tab name="2: Javascript"><source lang="javascript"> | ||
basic.forever(function () { | basic.forever(function () { | ||
Riadok 110: | Riadok 112: | ||
</source></tab> | </source></tab> | ||
<tab name="Python"><source lang="python" style="background: LightBlue;"> | <tab name="2: Python"><source lang="python" style="background: LightBlue;"> | ||
# MindPlus | # MindPlus | ||
Riadok 125: | Riadok 127: | ||
</source></tab> | </source></tab> | ||
<tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk"> | <tab name="2: C++"><syntaxhighlight lang=c style="background: Cornsilk"> | ||
/*! | /*! | ||
* MindPlus | * MindPlus |
Verzia z 18:27, 24. máj 2020
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
-
Prvý program...
-
...bude vyzerať v simulátore takto.
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();
}
-
Prvý program...
-
...bude vyzerať v simulátore takto.
Zmurkajuci smajlik:
basic.forever(function () {
basic.showIcon(IconNames.Happy)
basic.pause(100)
basic.showLeds(`
. . . . .
. # . . .
. . . . .
# . . . #
. # # # .
`)
basic.pause(100)
})
# MindPlus
# microbit
from microbit import *
while True:
display.show(Image("00000:09090:00000:90009:09990"))
sleep(100)
display.show(Image("00000:00090:00000:90009:09990"))
sleep(100)
/*!
* MindPlus
* microbit
*
*/
#include <Microbit_Matrix.h>
// Static constants
const uint8_t bbcBitmap[][5] = {
{B00000,B01010,B00000,B10001,B01110},
{B00000,B00010,B00000,B10001,B01110}
};
// Main program start
void setup() {
}
void loop() {
MMatrix.show(bbcBitmap[0]);
delay(100);
MMatrix.show(bbcBitmap[1]);
delay(100);
}
-
Prvý program...
-
...bude vyzerať v simulátore takto.
Zakladne vypisy:
basic.showString("Result:")
basic.showNumber(3)
basic.showIcon(IconNames.Yes)
})
# MindPlus
# microbit
from microbit import *
display.scroll(str("Result: "), wait=False, loop=False)
display.scroll(str((str(3))), wait=False, loop=False)
display.show(Image("00000:00009:00090:90900:09000"))
/*!
* MindPlus
* microbit
*
*/
#include <Microbit_Matrix.h>
// Static constants
const uint8_t bbcBitmap[][5] = {
{B00000,B00001,B00010,B10100,B01000}
};
// Main program start
void setup() {
MMatrix.print("Result: ");
MMatrix.print((String(3)));
MMatrix.show(bbcBitmap[0]);
}
void loop() {
}
-
Prvý program...
-
...bude vyzerať v simulátore takto.
Visacka na diskoteku:
basic.showIcon(IconNames.Yes)
input.onButtonPressed(Button.A, function () {
basic.showIcon(IconNames.Happy)
})
input.onButtonPressed(Button.B, function () {
basic.showIcon(IconNames.Sad)
})
input.onButtonPressed(Button.AB, function () {
basic.showIcon(IconNames.Heart)
})
# MindPlus
# microbit
from microbit import *
def on_button_a():
while True:
if button_a.is_pressed():
yield callback_button_a()
else:
yield
def on_button_b():
while True:
if button_b.is_pressed() and not button_a.is_pressed():
yield callback_button_b()
else:
yield
# Event callback function
def callback_button_a():
global mind_n_myValue, mind_s_my_string_variable
display.show(Image("00000:09090:00000:90009:09990"))
def callback_button_b():
global mind_n_myValue, mind_s_my_string_variable
display.show(Image("00000:09090:00000:09990:90009"))
def callback_button_a():
global mind_n_myValue, mind_s_my_string_variable
display.show(Image("09090:99999:99999:09990:00900"))
func_button_a = on_button_a()
func_button_b = on_button_b()
display.show(Image("00000:00009:00090:90900:09000"))
while True:
next(func_button_a)
next(func_button_b)
/*!
* MindPlus
* microbit
*
*/
#include <Microbit_Matrix.h>
// Function declaration
void buttonACallback();
void buttonBCallback();
void buttonABCallback();
// Static constants
const uint8_t bbcBitmap[][5] = {
{B00000,B00001,B00010,B10100,B01000},
{B00000,B01010,B00000,B10001,B01110},
{B00000,B01010,B00000,B01110,B10001},
{B01010,B11111,B11111,B01110,B00100}
};
// Main program start
void setup() {
onEvent(ID_BUTTON_A, PRESS, buttonACallback);
onEvent(ID_BUTTON_B, PRESS, buttonBCallback);
onEvent(ID_BUTTON_AB, PRESS, buttonABCallback);
MMatrix.show(bbcBitmap[0]);
}
void loop() {
}
// Event callback function
void buttonACallback() {
MMatrix.show(bbcBitmap[1]);
}
void buttonBCallback() {
MMatrix.show(bbcBitmap[2]);
}
void buttonABCallback() {
MMatrix.show(bbcBitmap[3]);
}
-
Prvý program...
-
...bude vyzerať v simulátore takto.
Pocitadlo ludi pri vchode:
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)
})
# 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)
/*!
* 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;
}