4 Panel key detection

From Banana Pi Wiki
Revision as of 01:55, 18 February 2019 by Sinovoip (talk | contribs) (Created page with "=Panel key detection= Well, at least we've now created some code to get the board to do something. So, let's deal with device input, like keystroke input. First, we need to kn...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Panel key detection

Well, at least we've now created some code to get the board to do something. So, let's deal with device input, like keystroke input. First, we need to know two concepts: Output represents the Output from the device to the periphery, and Input represents some information received in the process of processing the device

So the most obvious input on the board is two buttons, two A and B buttons on the left and right of the light board. If we want to know whether the button on the board has been pressed, or whether it has been pressed, or how many times it has been pressed, how can we do that?

It's not so hard, it's easier said than done.

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

This code will pause for two seconds before you start pressing the button, which will scroll to show how many times you have pressed A. It's that simple. While the code isn't very useful, it does provide some new ideas about how you can control your hardware

  • 1,The sleep function allows the board to pause for a few milliseconds, the number of milliseconds in the block. If you want to pause at some point in your program, write the sleep function as shown above.
  • 2,The button_a object allows you to get the number of times pressed in a time via the get_presses method