1
0

More than 5 years have passed since last update.

RaspberryPiでLEDをチカチカさせるPythonプログラム(1)

Last updated at Posted at 2017-04-10

はじめまして!
『おっ、python と、Raspberry ぱい』というサイトでブログを書いている Az yocatterと申します。
ここでは『おっ、python と、Raspberry ぱい』をお色気を抜いてほぼそのままの内容で掲載しております。今後ともよろしくお願いします・・・ということで本題。

カラー図解 最新 Raspberry Piで学ぶ電子工作 作って動かしてしくみがわかる (ブルーバックス)の中に書いてある、第4章の2番目に書いてあったPythonのプログラムもちょいと改造しました。
(点滅間隔を0.5秒から0.2秒に変更し、さらに20回点滅してストップさせます。また、20回点滅の途中でctrl + Cを押してもエラーなくストップします。どやっw)

コード(python)は、以下の通りです。

led01.py
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)

try:
    c = 1
    while c <= 20:
        GPIO.output(25, GPIO.HIGH)
        sleep(0.2)
        GPIO.output(25, GPIO.LOW)
        sleep(0.2)
        c += 1

except KeyboardInterrupt:
    pass

GPIO.cleanup()

どうぞお試しあれ!

ということで、今回はこのへんで・・・。
最後までお読み頂き、誠にありがとうございました。

グラビアアイドルのお姉さんを眺めながら学びたいという方はこちら
http://oppython.wp.xdomain.jp/2017/03/24/post-36/

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0