Deutsch English |
YOU LEARN HERE... |
how to use the two micro:bit buttons to develop interactive programs. You will also learn how to play sound with your robot. |
HOW THE BUTTONS WORK |
|
EXAMPLES |
The commands for the buttons are in the microbit module, which you must also import. Example 2: Sound is played when a button is clicked
Program: from microbit import * from mbrobot import * #from mbrobot_plusV2 import * from music import * repeat: if button_a.was_pressed(): play(JUMP_UP) if button_b.was_pressed(): play(JUMP_DOWN) Example 3: Aborting a program with a button
Programm: from microbit import * from mbrobot import * #from mbrobot_plus import * setSpeed(30) forward() while not button_a.was_pressed(): d = getDistance() if d < 10: backward() delay(1000) forward() delay(200) stop() Example 4: Controlling the robot with buttons
Program: from microbit import * from mbrobot import * #from mbrobot_plus import * forward() repeat: v = irLeft.read_digital() if v == 0: backward() delay(500) stop() if button_a.was_pressed(): left() delay(550) forward() elif button_b.was_pressed(): right() delay(550) forward() sleep(10) |
REMIND YOU... |
You can use buttons to develop interactive programs. The is_pressed() function returns True if the button is pressed. The was_pressed() function returns True if the button has been clicked at any time since the program was started or since the last call. |
TO SOLVE IT YOURSELF |
|
Melodys, in Modul music :
ADADADUM - Beethoven 5. Sinfonie in C Moll
ENTERTAINER - Scott Joplin Ragtime
PRELUDE -J.S.Bach 48 Preludien and Fuges
ODE - Ode an Joy Thema aus Beethoven 9. Sinfonie in D Moll
NYAN - Nyan Cat Thema
RINGTONE - Phone
FUNK - secret agents
BLUES - ein Boogie-Woogie Blues
BIRTHDAY - Happy Birthday to You...
WEDDING - Wagner Oper Lohengrin
FUNERAL - Chopin Klaviersonate
PUNCHLINE - Tonclip
PYTHON - Monty Python Flying Circus
BADDY - The Baddy
CHASE - Jagdszene
BA_DING - Signaltone
WAWAWAWAA - Posaunenklang
JUMP_UP - for games, go up
JUMP_DOWN - for games, go down
POWER_UP - power up
POWER_DOWN - power downt