0
1

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プログラム(4)

Last updated at Posted at 2017-04-10

前回はブレットボードにLEDを6つ並べて、上から順番に点灯させましたが、今回は、ランダムに点灯させます。

こんな感じで点滅します。
https://youtu.be/nNMyl2Ehdvo

配線は前回と全く同じなので、RaspberryPiでLEDをチカチカさせるPythonプログラム(3)をご覧ください。

ソースは以下の通りです。

led04.py
import RPi.GPIO as GPIO
from time import sleep
import random

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


try:
    c  =  1
    s  =  0.1
    t  =  50
    r = random.choice(list_r)
    g = random.choice(list_g)    
    
    while c < t:
        GPIO.output(r, GPIO.HIGH)
        sleep(s)
        GPIO.output(g, GPIO.HIGH)
        sleep(s)
        GPIO.output(r, GPIO.LOW)
        sleep(s)
        GPIO.output(g, GPIO.LOW)
        sleep(s)
        r = random.choice(list_r)
        g = random.choice(list_g)
        c += 1
except KeyboardInterrupt:
    pass
GPIO.cleanup()

皆様お試しあれ

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

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

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?