-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbit_counter.py
More file actions
53 lines (40 loc) · 1.35 KB
/
bit_counter.py
File metadata and controls
53 lines (40 loc) · 1.35 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
import RPi.GPIO as GPIO
import time
#Setting up script to use the right pin configuration
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#Define some variables
LED_counter = 0 #The current number in decimal
bit_counter = 0 #The current bit
current_num = "" #The current number in binary
LED_array = [[17,0],[22,0],[6,0],[26,0]] #The LED configuration array
Pin_array = [17,22,6,26,4]
#Set all the pins to outputs
for index in range(len(Pin_array)):
GPIO.setup(Pin_array[index], GPIO.OUT)
#Reset all the pins to 0
def resetPins():
for index in range(len(Pin_array)):
GPIO.output(Pin_array[index], 0)
time.sleep(0.3)
return
#Turn the LEDs on or off
def makeitso(theLEDs = [], *args):
LED_counter = 0
while LED_counter < 4:
GPIO.output(theLEDs[LED_counter][0], theLEDs[LED_counter][1])
LED_counter += 1
time.sleep(.3)
return
#Define the pin configuration by counting in binary and stripping out each bit, char by char.
while LED_counter <= 15:
resetPins()
current_num = bin(LED_counter)[2:].zfill(4)
while bit_counter < 4:
LED_array[bit_counter][1] = int(current_num[bit_counter])
bit_counter += 1
bit_counter = 0
GPIO.output(Pin_array[4], 1)
makeitso(LED_array)
LED_counter += 1
GPIO.cleanup()