数码营电子:基于微型控制器的编程、电路设计与电子产品制做。邮箱:shumaying@hotmail.com

树莓派点亮LED灯

From 数码营电子实验室
Jump to navigation Jump to search

树莓派点亮LED灯

实物照
树莓派点亮LED灯-Raspberry pi 3 B+管脚分布图

代码:

import RPi.GPIO as GPIO    # Import Raspberry Pi GPIO library
from time import sleep     # Import the sleep function from the time module
GPIO.setwarnings(False)    # Ignore warning for now
GPIO.setmode(GPIO.BOARD)   # Use physical pin numbering
GPIO.setup(11, GPIO.OUT, initial=GPIO.LOW)   # Set pin 11 to be an output pin and set initial value to low (off). Note:Pins number read from LEFT to RIGHT, from TOP till BOTTOM.
while True: # Run forever
   GPIO.output(11, GPIO.HIGH) # Turn on
   sleep(0.5)                  # Sleep for 0.5 second
   GPIO.output(11, GPIO.LOW)  # Turn off
   sleep(0.5)                  # Sleep for 0.5 second

Operation in Command Line Interface:

Run programme:python Led_Blink-1.py
Stop running:ctrl+Z

Qrcode for gh a3b9e9962ce8 1280.jpg