![]() ![]() Utime.sleep(5) #When the green light is next to the red light, the green light is off first, the yellow light is on for two seconds, and then the red light is onĬonnect the boards as in the picture below. Led_red.value(1) #Under normal circumstances, the yellow light will be on for two seconds when the red light is next to the green light, then the yellow and red lights will be off, and the green light will be on If button_pressed = True: #If the button is pressed, the red light is on and the buzzer sounds _thread.start_new_thread(button_reader_thread, ()) #Use the method of starting the thread to detect the button Precautions for use: The longer pin of the LED is the positive pole, the shorter one is the negative pole, the negative pole should be connected to GND, the positive pole should be connected to the GPIO output port, and a resistor must be connected when using it the red line of the buzzer is connected to the GPIO port output, black The line is connected to GND.ĭef button_reader_thread(): #Detect if the button is pressed.Connect the hardware according to the figure below, connect the Micro USB to the computer, open the python file in the sample program Lesson-9 Traffic-Light-System in Thonny, and run the program, you can see the normal operation of the traffic light strip, when you press the button will trigger the buzzer.Led_external.toggle() #Change the state of the LED light every 5 seconds Led_external = machine.Pin(15, ) #Set GP15 as output mode Precautions for use: The longer pin of the LED is the positive pole, the shorter one is the negative pole, the negative pole should be connected to GND, and the positive pole should be connected to the GPIO output port, and a resistor must be connected when using.Connect to PC by Micro USB, and open the python file in the sample program Lesson-5 External LED in Thonny, and run the sample program to see that the red light is flashing. Connect the hardware according to the following figure.Download example demo to the desktop for testing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |