-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLED_Fun3.py
More file actions
executable file
·57 lines (48 loc) · 1.42 KB
/
LED_Fun3.py
File metadata and controls
executable file
·57 lines (48 loc) · 1.42 KB
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
#!/usr/bin/env python
#
# Raspberry Pi Class.
# David M. N. Bryan, dave@drstrangelove.net
#
# This is licend under creative commons license:
# http://creativecommons.org/licenses/by-nc-sa/3.0/
# Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
#
#import the Raspberry Pi GPIO Library
import RPi.GPIO as GPIO
import time
# Define OUTPUT Pins on RPI for the LEDs
GPIORed_PIN=27
GPIOGreen_PIN=17
GPIOBlue_PIN=22
# How about some input please?
# This will define what pin we want to use for a button input...
BUTTON1_PIN=24
# How long do we sleep between cycles, we can set this to .25 for 1/4
# of a second.
SLEEP_TIME=1
# Set the pins on the GPIO up.
# Setup the OUTPUTS (LEDS)
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIORed_PIN, GPIO.OUT)
GPIO.setup(GPIOGreen_PIN, GPIO.OUT)
GPIO.setup(GPIOBlue_PIN, GPIO.OUT)
#Setup the INPUTs (Buttons)
GPIO.setup(BUTTON1_PIN, GPIO.IN)
# Do this thing that I say until someone kills this loop...
while True:
# Has the button been pushed?
if ( GPIO.input(BUTTON1_PIN) == True ):
# Looks like it was pushed, and while it's still pushed, lets
# make some pretty blinks...
# All on!
GPIO.output(GPIORed_PIN, True)
GPIO.output(GPIOGreen_PIN, True)
GPIO.output(GPIOBlue_PIN, True)
# ZZzzzzzzz....
time.sleep(SLEEP_TIME)
# All off!
GPIO.output(GPIORed_PIN, False)
GPIO.output(GPIOGreen_PIN, False)
GPIO.output(GPIOBlue_PIN, False)
# Sleeepy time..zzzz
time.sleep(SLEEP_TIME)