Raspberry Pi 3 includes a library to operate GPIO from python as standard
GPIO.setmode (GPIO.BOARD)
--GPIO.BOARD: Physical pin number (serial number from top left)
--GPIO.BCM: Role pin number (named by broadcom)GPIO.setup (channel, GPIO.out)
--GPIO.in: Input
--GPIO.out: Outputled-blink.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
while True:
GPIO.output(11, True)
time.sleep(2)
GPIO.output(11, False)
time.sleep(2)
led-blink.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
time.sleep(0.2)
Recommended Posts