Žmurkajúci smajlík: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 24: | Riadok 24: | ||
</source></tab> | </source></tab> | ||
<tab name="Python"><source lang="python" style="background: LightBlue;"> | <tab name="MS Python"><source lang="python" style="background: LightBlue;"> | ||
def on_forever(): | |||
basic.show_icon(IconNames.HAPPY) | |||
basic.pause(500) | |||
basic.show_leds(""" | |||
. . . . . | |||
. # . . . | |||
. . . . . | |||
# . . . # | |||
. # # # . | |||
""") | |||
basic.pause(100) | |||
basic.forever(on_forever) | |||
</source></tab> | |||
<tab name="uPython"><source lang="python" style="background: LightBlue;"> | |||
from microbit import * | from microbit import * | ||
Verzia z 17:13, 21. jún 2020
Žmurkajúci smajlík je jednoduchá animácia, v ktorej sa striedajú dva smajlíky - jeden normálny a jeden so zhasnutým očkom. Je to zároveň príklad na vytvorenie vlastného obrázku, pretože ten jednooký sa medzi predpripravenými obrázkami nenachádza.
-
Program v blokovom jazyku
-
a jeho funkcia
basic.forever(function () {
basic.showIcon(IconNames.Happy)
basic.pause(100)
basic.showLeds(`
. . . . .
. # . . .
. . . . .
# . . . #
. # # # .
`)
basic.pause(100)
})
def on_forever():
basic.show_icon(IconNames.HAPPY)
basic.pause(500)
basic.show_leds("""
. . . . .
. # . . .
. . . . .
# . . . #
. # # # .
""")
basic.pause(100)
basic.forever(on_forever)
from microbit import *
while True:
display.show(Image.HAPPY)
sleep(1000)
display.show(Image('00000:'
'09000:'
'00000:'
'90009:'
'09990'))
sleep(200)
#include <Adafruit_Microbit.h>
Adafruit_Microbit_Matrix microbit;
const uint8_t SMILE_1[] =
{ B00000,
B01010,
B00000,
B10001,
B01110,
};
const uint8_t SMILE_2[] =
{ B00000,
B01000,
B00000,
B10001,
B01110,
};
void setup() {
microbit.begin();
}
void loop() {
microbit.show(SMILE_1);
delay(1000);
microbit.show(SMILE_2);
delay(200);
}
#include "MicroBit.h"
MicroBit uBit;
MicroBitImage SMILEY1("0,1,0,1,0 \n"
"0,1,0,1,0 \n"
"0,0,0,0,0 \n"
"1,0,0,0,1 \n"
"0,1,1,1,0 \n");
MicroBitImage SMILEY2("0,0,0,1,0 \n"
"0,0,0,1,0 \n"
"0,0,0,0,0 \n"
"1,0,0,0,1 \n"
"0,1,1,1,0 \n");
int main()
{
uBit.init(); // setup
while(1) // loop
{
uBit.display.print(SMILEY1);
uBit.sleep(1000);
uBit.display.print(SMILEY2);
uBit.sleep(200);
}
}
Späť na zoznam príkladov....