2019 views|1 replies

55

Posts

0

Resources
The OP
 

Micropython TurnipBit Youth Beginner Programming Traffic Light Experiment [Copy link]

 
I don't know if you have studied the principle of traffic lights when you were young. I was a child from the countryside and didn't see real traffic lights until junior high school. I remember it very clearly. I stood at that intersection for five or six minutes and stared at the traffic lights changing. I couldn't figure out the principle, but I just felt it was magical. Now it's really funny. A big part of the reason I wrote this today was for my childhood self. The principle is very simple. I don't call it a tutorial, I call it the key to open the door to youth programming.
Required original components:
One TurnipBit
One TurniPBit expansion board
Several light emitting diodes
Several Dupont lines
A USB data cable
A breadboard
1k resistor (LEDs are easy to burn)
Experimental steps:
1. Plug three LEDs into the breadboard, with the negative pole of the LED plugged into the negative pole of the breadboard (horizontal jack), and the positive pole plugged into the vertical jack of the breadboard.
2. Insert the 1k resistor into the negative pole of the breadboard (horizontal jack) and the vertical jack, and connect the positive pole of the LED to the pins of the TurnipBit expansion board respectively.
3. Connect the positive poles of the red, yellow and green LED lights to the P0, P1 and P2 pins of the TurnipBit expansion board through DuPont wires in turn, and then connect the vertical jack of the resistor to the GND pin of the TurnipBit expansion board with a DuPont wire.
4. Wiring method:
The correspondence between the TurnipBit expansion board and the LED interface is as follows:
Turnip expansion board
[align= left]LED
PO
[align= left]
Red light positive pole
P1
[align= left]
Yellow light positive pole
P2
[align= left]
Green light positive pole
GND
[align= left]
GND
Fritzing picture Tips: (If you want to learn this, you can read my previous article introducing fritzing, which is very interesting) #333333]
[align =left]
[ size=18px]5. Source code:
[size=18px ]Write code with TurnipBit visual programming
Open TurnipBit visual programming address http://www.turnipbit.com/
[align= left]
Source code:
from microbit import *
while True:
pin0.write_digital(1)
[ size=18px] pin1.write_digital(0)
pin2.write_digital(0)
[size= 18px] sleep(5000)
[size= 18px] pin0.write_digital(0)
[ size=18px] pin1.write_digital(1)
[ size=18px] sleep(2000)
[size= 18px] pin1.write_digital(0)
[ size=18px] pin2.write_digital(1)
[ size=18px] sleep(5000)
[size= 18px]
[/ size]
Visual Programming Figure
[ attach]589864[/attach]
[align =left]Then the simulated traffic light is ready. Isn't it very simple?[/ backcolor]write_digital(1)
sleep(5000)
Visual Programming Diagram
Then the simulated traffic light is ready. Isn't it simple?
write_digital(1)
sleep(5000)
Visual Programming Diagram
Then the simulated traffic light is ready. Isn't it simple?

Latest reply

have a look  Details Published on 2018-3-16 11:04
 
 

1903

Posts

0

Resources
2
 
have a look
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list