0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-04-10

前回は2つを交互に点灯させてみましたが、今回は6つに増やし、上から順番に点灯→消灯します。

youtubeに動画をご用意いたしました。
https://youtu.be/Z6QAQjGlTH8

GPIO(赤い線のほう)から抵抗を伝わってLEDに電気が通り、GNDへ流れていくという回路です。
(これが6つ並んでおります)

001.jpg

この並んでいるランプを上から順番につけ、そして消してから次のLEDを点灯させるというPythonのプログラムでございます。

コードはこちら

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

ch_list = [4, 17, 5, 27, 25, 24]
GPIO.setmode(GPIO.BCM)
GPIO.setup(ch_list, GPIO.OUT)

try:
    c  =  0
    s  =  0.1
    t  =  10
    while c < t:
        GPIO.output(4, GPIO.HIGH)
        sleep(s)
        GPIO.output(4, GPIO.LOW)
        sleep(s)
        GPIO.output(17, GPIO.HIGH)
        sleep(s)
        GPIO.output(17, GPIO.LOW)
        sleep(s)
        GPIO.output(5, GPIO.HIGH)
        sleep(s)
        GPIO.output(5, GPIO.LOW)
        sleep(s)
        GPIO.output(27, GPIO.HIGH)
        sleep(s)
        GPIO.output(27, GPIO.LOW)
        sleep(s)        
        GPIO.output(25, GPIO.HIGH)
        sleep(s)
        GPIO.output(25, GPIO.LOW)
        sleep(s)
        GPIO.output(24, GPIO.HIGH)
        sleep(s)
        GPIO.output(24, GPIO.LOW)
        sleep(s)

        c += 1

except KeyboardInterrupt:
    pass

GPIO.cleanup()

皆様お試しあれ

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

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

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?