Newer
Older
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
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# Import the GPIO module and set the board layout:
# <codecell>
import random
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# <markdowncell>
# Initialize the Pins:
# <codecell>
red=27
blue=18
yellow=22
pins = [red,blue,yellow]
GPIO.setup(red, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)
GPIO.setup(yellow, GPIO.OUT)
def turn_off():
for pin in pins:
GPIO.output(pin, False)
turn_off()
# <markdowncell>
# Now switch the LEDs:
# <codecell>
GPIO.output(red, True)
GPIO.output(yellow, False)
GPIO.output(blue, True)
# <codecell>
for i in range(100):
pin = random.choice(pins)
mode = random.choice((True, False))
GPIO.output(pin, mode)
time.sleep(0.1)
print 'done'
turn_off()
# <codecell>