Buttons button

 

To date, we've written some code, but are only output, however, sometimes we also want to be able to deal with some input board, input and output we are speaking for the board. Microbit two keys on the input board is the most prominent, are A and B, mPython can handle two keys.

Also relevant is simple:

from microbit import *
sleep(1000)
display.scroll(str(button_a.get_presses()))

Code 1000 ms pause, i.e. after one second, the number of scroll button A is pressed.

sleep () function is the number of milliseconds temporary code execution means, any method is not the object, but functionally similar

button_a is an object, I get the number of keystrokes by its get_presses method.

str () function to a digital conversion to a string, because the method must be display.scroll parameter string

The third row has many layers brackets, sometimes as onion skin, surrounded by a laminated, code execution, when viewed beginning from the innermost, layer by layer removal of outer bracket performed. Also a bit like Russian dolls.

Suppose you press the A button 10 times, the code is executed.

display.scroll(str(button_a.get_presses()))
display.scroll(str(10))
display.scroll("10")

Looks complicated, in fact, the implementation of the program will soon be finished.

Guess you like

Origin www.cnblogs.com/qywyll/p/11810798.html