In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces "how to use MicroPython neopixle" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this "how to use MicroPython neopixle" article can help you solve your doubts.
Microbit/newbit MicroPython firmware, built-in control of neopixel lights, we can use any GPIO to control neopixel, support any number of lights.
Import neopixelnp = neopixel.NeoPixel (pin1, 8) np [0] = (0,0,200) np [1] = (0,50,100) np [2] = (200,0,0) np.show ()
The function neopixel.NeoPixel (PIN, NUM) is used to create a neopixel object, which takes two parameters, the first is the GPIO, and the second is the number of colored lights.
The neopixel object is a list of tuples, and each list item is a tuple of three colors of RGB. The RGB parameter ranges from 0 to 255. the combination of the three colors has 256 x 256 x 256 = 1.67m colors.
The color parameter cannot be changed after the color parameter is written into the list, and the function show () needs to be called before it is updated. If you want to clear the lights, you can call the function clear ().
Official example, random display of colored lights.
"" neopixel_random.py Repeatedly displays random colours onto the LED strip. This example requires a strip of 8 Neopixels (WS2812) connected to pin0. "" from microbit import * import neopixelfrom random import randint# Setup the Neopixel strip on pin0 with a length of 8 pixelsnp = neopixel.NeoPixel (pin0, 8) while True: # Iterate over each LED in the strip for pixel_id in range (0, len (np)): red = randint (0,60) green = randint (0,60) blue = randint (0,60) # Assign the current LED a random red Green and blue value between 0 and 60 NP [pixel _ id] = (red, green, blue) # Display the current pixel data on the Neopixel strip np.show () sleep
Graphical programming
Corresponding mpy code:
Import neopixelimport randomfrom microbit import * np = neopixel.NeoPixel (pin0, 8) while True: np [(random.randint (0,7)] = ((random.randint (1,50)), (random.randint (1,50)), (random.randint (1,50) np.show () sleep
If you directly use the 3.3V power supply of microbit/newbit, be careful not to control too much LED, because the output power of LDO is limited, it is easy to cause overheat protection. It is best to use an external power source for more than 8 LED.
After reading this, the article "how to use MicroPython neopixle" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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: 241
*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.