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 | | [align= left] Red light positive pole | | [align= left] Yellow light positive pole | | [align= left] Green light positive pole | | [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 [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?
|