In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the Python development of TPYBoard development board how to DIY traffic lights, the article is rich in content and professional analysis and description for you, after reading this article, I hope you can get something.
Water lamp is probably the most frequent DIY thing, one is because it is simple and easy to achieve, and the other is that the effect is good. In order to demonstrate the powerful functions of MicroPython and show different uses, let's use the TPYBoard development board to DIY a small traffic light board to experience the charm of python development.
About TPYBoard
TPYBoard single-chip microcomputer development board, the existing TPYBoardV101, v102 two versions, of which v102 is the upgraded version of v101, adding swd interface. Using python development language, provides 30 GPIO, easy to use python to develop Internet of things products. Support Python3.0 and above version of direct operation, support gravity accelerometer, support hundreds of peripheral accessories. For more details, tutorials and examples, please refer to the micropython website http://www.micropython.net.cn
1. Experimental purpose
1. Learn the method of extending the simple Iripple O interface in the PC system.
two。 Further learn the design method of compiling data output program.
3. Learn the method of simulating traffic light control.
two。 Required components
220 euro resistor
A red LED digital tube
A piece of bread
TPYBoard board
A data line
Red, green and yellow led lights
Some DuPont lines
3. Turn on the led lamp
Three led lights are plugged into the bread board, the led negative electrode is inserted into the negative electrode of the bread board (horizontal Jack), and the positive electrode is inserted into the longitudinal insertion of the bread board. The 222ohm resistance is inserted into the negative electrode (horizontal Jack) and longitudinal Jack of the bread board, and the positive pole of the led lamp is connected with the TPYBoard pin respectively, because to make the traffic light, only three pins are needed. I use Y1, Y2, Y3 pins. Connect the positive electrodes of three led lights to the pins of Y1, Y2 and Y3 of TPYboard through DuPont wire, then connect the resistance longitudinal Jack to the GND pin of TPYboard with DuPont wire, and raise the level of Y1, Y2 and Y3 pins in the main.py file, you can see that the three lights light up at the same time. The code is:
# main.py-put your code here!
Import pyb
Led1 = pyb.Pin ("Y1", pyb.Pin.OUT_PP)
Led2 = pyb.Pin ("Y2", pyb.Pin.OUT_PP)
Led3 = pyb.Pin ("Y3", pyb.Pin.OUT_PP)
While True:
Led1.value (1)
Led2.value (1)
Led3.value (1)
4. Light up the digital tube
The SM42056 is a 0.56-inch common-cathode / red LED digital tube. There are ten pins. When the decimal point is in the lower right corner of you, the top row of five pins, from left to right, is ggraine f, Di, aMagib, and the lower row of five pins, from left to right, is ePergent d, Di, cMagne DP. If we want the digital tube to light up, all we need to do is to pull up the level in main.py, connect the ground to the GND pin of TPYboard, and it will be displayed as 8. As shown below:
The following is the high level of the pin corresponding to the 0-9 number, that is, the pin pull level corresponding to the TPYboard
Digital high level pin
0 a,b,c,d,e,f
1 e,f
2 a,b,g,e,d
3 a,b,g,c,d
4 b,c,g,f
5 a,f,g,c,d
6 a,f,e,d,c,g
7 a,b,c
8 a,b,c,d,e,f,g
5. Simulated traffic light
After we have finished following the above steps, then turn on the power and modify the main.py file to make the lamp change with the change of the digital tube. The specific code is as follows:
# main.py-put your code here!
Import pyb
Led1 = pyb.Pin ("Y1", pyb.Pin.OUT_PP)
Led2 = pyb.Pin ("Y2", pyb.Pin.OUT_PP)
Led3 = pyb.Pin ("Y3", pyb.Pin.OUT_PP)
X1 = pyb.Pin ("X1", pyb.Pin.OUT_PP)
X2 = pyb.Pin ("X2", pyb.Pin.OUT_PP)
X3 = pyb.Pin ("X3", pyb.Pin.OUT_PP)
X4 = pyb.Pin ("X4", pyb.Pin.OUT_PP)
X5 = pyb.Pin ("X5", pyb.Pin.OUT_PP)
X6 = pyb.Pin ("X6", pyb.Pin.OUT_PP)
X8 = pyb.Pin ("X8", pyb.Pin.OUT_PP)
Def six ():
X1.value (1)
X2.value (1)
X3.value (1)
X5.value (1)
X6.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X2.value (0)
X3.value (0)
X6.value (0)
X5.value (0)
X8.value (0)
Def nine ():
X1.value (1)
X2.value (1)
X3.value (1)
X4.value (1)
X5.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X2.value (0)
X3.value (0)
X4.value (0)
X5.value (0)
X8.value (0)
Def eight ():
X1.value (1)
X2.value (1)
X3.value (1)
X4.value (1)
X5.value (1)
X6.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X2.value (0)
X3.value (0)
X4.value (0)
X5.value (0)
X6.value (0)
X8.value (0)
Def zero ():
X2.value (1)
X3.value (1)
X4.value (1)
X5.value (1)
X6.value (1)
X8.value (1)
Pyb.delay (1000)
X2.value (0)
X3.value (0)
X4.value (0)
X5.value (0)
X6.value (0)
X8.value (0)
Def seven ():
X3.value (1)
X4.value (1)
X8.value (1)
Pyb.delay (1000)
X3.value (0)
X4.value (0)
X8.value (0)
Def five ():
X1.value (1)
X2.value (1)
X3.value (1)
X5.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X2.value (0)
X3.value (0)
X5.value (0)
X8.value (0)
Def four ():
X1.value (1)
X2.value (1)
X4.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X2.value (0)
X4.value (0)
X8.value (0)
Def three ():
X1.value (1)
X3.value (1)
X4.value (1)
X5.value (1)
X8.value (1)
Pyb.delay (1000)
X1.value (0)
X4.value (0)
X3.value (0)
X5.value (0)
X8.value (0)
Def two ():
X1.value (1)
X3.value (1)
X4.value (1)
X5.value (1)
X6.value (1)
Pyb.delay (1000)
X1.value (0)
X3.value (0)
X4.value (0)
X5.value (0)
X6.value (0)
Def one ():
X2.value (1)
X6.value (1)
Pyb.delay (1000)
X2.value (0)
X6.value (0)
While True:
Led1.value (1)
Nine ()
Eight ()
Seven ()
Six ()
Five ()
Four ()
Three ()
Two ()
One ()
Zero ()
Led1.value (0)
Led2.value (1)
Nine ()
Eight ()
Seven ()
Six ()
Five ()
Four ()
Three ()
Two ()
One ()
Zero ()
Led2.value (0)
Led3.value (1)
Three ()
Two ()
One ()
Zero ()
Led3.value (0)
The above is the editor for you to share the Python development TPYBoard development board how to DIY the traffic light, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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: 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.