In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use micropython on newbit". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use micropython on newbit".
There is a LED array of 5x5 on newbit, which can display small graphics and text, and the display effect is good.
In micropython, a special library has been designed for LED, which can be easily displayed. Most of the time, the display function is completed with only one command. For example, the following code shows the scrolling text Hello, wordwords:
From microbit import * display.scroll ("Hello, World!")
This is displayed at the default speed. If you want to speed up or slow down, you can add the parameter delay, such as:
Display.scroll ("Hello, World!", delay=50)
The default delay is 150, and scrolling will be faster when it is set to 50.
If you want the loop to display, you can add the loop parameter, and you can only return REPL through ctrl-C.
Display.scroll ("Hello, World!", loop=True)
The characters displayed by default are not equal in width and sometimes inconvenient. At this point, you can use an equal width font:
Display.scroll ("Hello, World!", monospace=True)
By default, the display.scroll function does not return until the display is complete, which is equivalent to working in blocking mode. You can also change to non-blocking mode so that after entering commands, the display can be done in the background, while REPL can continue to enter other commands. Blocking and non-blocking are specified by the parameter wait.
Display.scroll ("Hello, World!", wait=False)
The display.scroll function does not support Chinese and special characters.
Note that in microbit's micropython, there are no common modules such as pyb, machine, and so on. Instead, the microbit library is used.
Display.scroll can only display text, if you need to display graphics, you should use another function display.show, which can display text, graphics, but not scrolling, can only display one icon or character at a time. Such as:
Display.show ("Hello, World!") display.show (Image.HEART)
Dozens of icons are built into the microbit library, which can display commonly used emoticons, clocks, arrows, and so on. You can view the built-in icons through the dir or tab key.
The display.show function also supports parameters such as delay, loop, wait, and so on, similar to the display.scroll function. But display.show also has a special feature that allows you to display a set of icons at a time, such as:
Display.show ((Image.YES, Image.NO, Image.MEH))
In addition to the built-in graphics, we can also define our own graphics, such as:
Ico=Image ('11111ico 12345) display.show (ico)
Each graph needs to define five parameters, each separated by a colon, representing a line of LED, and the number represents the brightness of the LED.
We can also directly manipulate each LED, such as:
Display.set_pixel (1,1,2)
The first two parameters are the Xram Y coordinates, and the third parameter is the brightness (0-9, the larger the number, the brighter). You can also use the display.get_pixel function to read the brightness of the LED.
Other common functions:
Clear the screen, display.clear ()
Turn off the display (not clear), display.off ()
Turn on display, display.on ()
Thank you for your reading, the above is the content of "how to use micropython on newbit", after the study of this article, I believe you have a deeper understanding of how to use micropython on newbit, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.