Operácie

Kurz micro:bit: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Bez shrnutí editace
Balogh (diskusia | príspevky)
 
(10 medziľahlých úprav od rovnakého používateľa nie je zobrazených.)
Riadok 40: Riadok 40:
## Bluetooth
## Bluetooth
# Vlastný projekt
# Vlastný projekt
__TOC__




Riadok 83: Riadok 85:
</tabs>
</tabs>


=='''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]]


<gallery heights=200px mode="packed">  <!-- slideshow? -->
Image:microbit-WinkSmiley.png|''Prvý program...''
Image:microbit-WinkSmileyRun.png|''...bude vyzerať v simulátore takto.''
</gallery>


Zmurkajuci smajlik:
Pre pokročilých


<tabs>
# [[Datalogger cez rádiový prenos]]
<tab name="2: Javascript"><source lang="javascript">
# [[Datalogger so záznamom]]
   
basic.forever(function () {
    basic.showIcon(IconNames.Happy)
    basic.pause(100)
    basic.showLeds(`
        . . . . .
        . # . . .
        . . . . .
        # . . . #
        . # # # .
        `)
    basic.pause(100)
})
 
</source></tab>
<tab name="2: Python"><source lang="python" style="background: LightBlue;">


# MindPlus
# microbit
from microbit import *


'''Robotika'''


while True:
# [[Kitronik :MOVE mini MK2]]
  display.show(Image("00000:09090:00000:90009:09990"))
# [[DF Robot Maqueen Lite‎‎]]
  sleep(100)
# [[Elecfreaks_ring:bit_Car]]
  display.show(Image("00000:00090:00000:90009:09990"))
# [[Elecfreaks wukong board]]
  sleep(100)
           
 
<!-- **************************************************************************** -->
 
</source></tab>
<tab name="2: C++"><syntaxhighlight lang=c style="background: Cornsilk">
/*!
* 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);
}
 
</syntaxhighlight></tab>
</tabs>
 




<!-- **************************************************************************** -->
<!-- **************************************************************************** -->


 
[[Súbor:microbit-XXX.png]][[Súbor:microbit-XXXRun.png]]
[[Súbor:microbit-DisplayMisc.png]][[Súbor:microbit-DisplayMiscRun.png]]
 
 


<gallery heights=200px mode="packed">  <!-- slideshow? -->
<gallery heights=200px mode="packed">  <!-- slideshow? -->
Image:microbit-DisplayMisc.png|''Prvý program...''
Image:microbit-XXX.png|''Prvý program...''
Image:microbit-DisplayMiscRun.png|''...bude vyzerať v simulátore takto.''
Image:microbit-XXXRun.png|''...bude vyzerať v simulátore takto.''
</gallery>
</gallery>


Zakladne vypisy:
Prazdny


<tabs>
<tabs>
<tab name="Javascript"><source lang="javascript">
<tab name="Javascript"><source lang="javascript">
   
basic.showString("Result:")
basic.showNumber(3)
basic.showIcon(IconNames.Yes)


})
    
    
</source></tab>
</source></tab>
<tab name="Python"><source lang="python" style="background: LightBlue;">
<tab name="Python"><source lang="python" style="background: LightBlue;">


# 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"))




</source></tab>
</source></tab>
<tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk">
<tab name="Arduino C++"><syntaxhighlight lang=c style="background: Cornsilk">
/*!
* 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() {
 
}


</syntaxhighlight></tab>
</syntaxhighlight></tab>
</tabs>
</tabs>


<tab name="mBED C++"><syntaxhighlight lang=c style="background: Cornsilk">


 
/* */  
 
 
 
<!-- **************************************************************************** -->
 
<gallery heights=200px mode="packed">  <!-- slideshow? -->
Image:microbit-WinkSmiley.png|''Prvý program...''
Image:microbit-WinkSmileyRun.png|''...bude vyzerať v simulátore takto.''
</gallery>
 
Visacka na diskoteku:
 
<tabs>
<tab name="Javascript"><source lang="javascript">
 
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)
})
 
 
</source></tab>
<tab name="Python"><source lang="python" style="background: LightBlue;">
# 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)
</source></tab>
<tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk">
/*!
* 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]);
}
 
 
</syntaxhighlight></tab>
</syntaxhighlight></tab>
</tabs>
</tabs>


<!-- **************************************************************************** -->
<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)
})


 
👉 Späť na [[Kurz micro:bit#Zbierka príkladov|zoznam príkladov....]]
</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]]
<gallery heights=200px mode="packed">  <!-- slideshow? -->
Image:microbit-PeopleCounter.png|''Prvý program...''
Image:microbit-PeopleCounterRun.png|''...bude vyzerať v simulátore takto.''
</gallery>
Prazdny
<tabs>
<tab name="Javascript"><source lang="javascript">
 
</source></tab>
<tab name="Python"><source lang="python" style="background: LightBlue;">
# *******
</source></tab>
<tab name="C++"><syntaxhighlight lang=c style="background: Cornsilk">
/* */
</syntaxhighlight></tab>
</tabs>
[[Category:micro:bit]]
[[Category:micro:bit]]

Aktuálna revízia z 17:40, 18. marec 2024

Pozrite sa, čo všetko sa dá robiť s mikrobitmi...


Obsah

  1. Čo je to physical computing? Interaktivita v umení, priemysle, vzdelávaní.
  2. Zoznámte sa s BBC micro:bit - Tour de Board.
    1. Displej a tlačidlá
    2. Napájanie a konektory
    3. Senzory
    4. Komunikačné možnosti
  3. Začíname. Prvý program.
  4. Možnosti programovania: Microsoft Blocks, Javascript, Python, C++
  5. Vstupy a výstupy
    1. Displej, LED diódy
    2. Tlačidlá, jednoduché senzory
    3. Externé zariadenia
  6. Senzory
    1. Snímač tlaku
    2. Snímač zrýchlenia
    3. Kompas
    4. Snímač teploty
    5. Snímač osvetlenia
  7. Komunikácia
    1. Sériová linka a USB
    2. Rádio
    3. Bluetooth
  8. 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

  1. Žmurkajúci smajlík
  2. Rozličné výpisy
  3. Visačka na diskotéku
  4. Počítadlo návštevníkov
  5. Kuchynské minútky


Pre pokročilých

  1. Datalogger cez rádiový prenos
  2. Datalogger so záznamom


Robotika

  1. Kitronik :MOVE mini MK2
  2. DF Robot Maqueen Lite‎‎
  3. Elecfreaks_ring:bit_Car
  4. Elecfreaks wukong board



Súbor:Microbit-XXX.pngSúbor:Microbit-XXXRun.png

Prazdny

# *******
/* */
/* */

</tabs>


👉 Späť na zoznam príkladov....