-
Notifications
You must be signed in to change notification settings - Fork 1
/
m_001_LED_flash.py
77 lines (57 loc) · 1.38 KB
/
m_001_LED_flash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! python3
# Filename: m_001_LED_flash
__author__ = "raspython"
__date__ = '2020/05/06 08:25'
import RPi.GPIO as GPIO
from time import sleep
def main():
"""
本体
"""
"""
変数定義
"""
# 設定時間
flash_time = 0.5
off_time = 0.5
"""
PIN NOの定義
"""
# LED
led_red = 13
led_blue = 19
led_green = 26
"""
GPIOの初期設定
"""
# PIN_NOの設定
GPIO.setmode(GPIO.BCM)
# LEDへの出力
GPIO.setup(led_red, GPIO.OUT)
GPIO.setup(led_blue, GPIO.OUT)
GPIO.setup(led_green, GPIO.OUT)
"""
実行部
"""
try:
# LEDを光らせる順番でGPIOのNOをリストに格納
flash_no = [led_red, led_blue, led_green,
[led_red, led_blue], [led_red, led_green],
[led_blue, led_green], [led_red, led_blue, led_green]]
print(len(flash_no))
# 5回繰り返す
for i in range(5):
# リストの要素を渡してループ
for n in flash_no:
# LEDの点灯
GPIO.output(n, GPIO.HIGH)
sleep(flash_time)
# LEDの消灯
GPIO.output(n, GPIO.LOW)
# sleep(off_time)
flash_time -= 0.1
except KeyboardInterrupt:
pass
GPIO.cleanup()
if __name__ == '__main__':
main()