Selasa, 15 November 2016

Raspberry PI First GPIO


sudo apt-get install python-dev
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo pip install virtualenv


Membuat Blinken GPIO
mkdir blinken
cd blinken
virtualenv env
. env/bin/activate
pip install rpi.gpio


ketik : vi blink.py

# Code goes here.
import RPi.GPIO as GPIO
import time

# Variable for the GPIO pin number
LED_pin_red = 21

# Tell the Pi we are using the breakout board pin numbering
GPIO.setmode(GPIO.BCM)

# Set up the GPIO pin for output
GPIO.setup(LED_pin_red, GPIO.OUT)

# Loop to blink our led
while True:
    GPIO.output(LED_pin_red, GPIO.HIGH)
    print("On")
    time.sleep(1)
    GPIO.output(LED_pin_red, GPIO.LOW)
    print("Off")
    time.sleep(1)


Tidak ada komentar:

Posting Komentar