Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read Matrix Keyboard with microbit and makecode

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use microbit and makecode to read matrix keyboards. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

I started making a simple pocket calculator using microbits back in 2018, and what's been bothering me ever since is connecting the numeric keypad to the microbit. Not only one or two additional buttons, but also 10, 12 or even 16 buttons can make the microbit calculator easier to use.

BBC microbit has only three main GPIO (Universal input and output) pins for connecting to the outside, which is really not enough. If you use an extension connector, you can access more GPIO.

Some projects use resistors of different values to reduce the number of pins required. If they are connected together but use different resistors, determine which button is pressed by measuring the analog input voltage.

I used another approach: the matrix button. Although you can buy a cheap matrix keyboard, I happen to have a small button in a large bag, so I decided to use a bread board and some wires to connect my matrix. Ordinary calculators and computer keyboards use matrices to reduce the wiring required to connect physical buttons to computing systems, so I learned something about them working at the bottom. The left side of each button is connected in a column. Then I lined up the right side of each button. Now, it seems that this requires a large number of pins, but imagine that if you connect each button separately, you need 4 3 × 4 arranged buttons and 12 pins. Using the scan matrix means you only need seven pins, one per row and one per column:

You must choose the pins of the microbit carefully because some pins are used for other functions such as display. The keyboard only needs digital pins, sends a row of digital signal output in turn, and then scans each column of the row with digital input to see if any keys have been pressed.

I selected pins 0, 1, 2, and 8 for the row and 16, 13, and 14 for the column. Pins 13 and 14 are also used for the SPI interface, but I don't use SPI here, so I can use them as GPIO pins. I may eventually need a 4 × 4 matrix to add action keys, but this will require a larger bread board. Now it's just a proof of concept, not a real work.

To verify the concept, I wrote a simple MakeCode program that sends digital write signals on each row in turn, and if a signal is entered on any column, the corresponding symbols on the display screen.

Note: the speed is slow. You must hold down each button for quite a long time. Part of the reason is that the "forever" block of MakeCode introduces a small amount of delay in the program. You can solve this problem by placing a "while true" block within an infinite loop block, but another benefit of a small delay is that you can see the scanning process in the simulator.

After reading the above, do you have any further understanding of how to read the matrix keyboard with microbit and makecode? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report