1
- # K.I.T.T. BikeLight
1
+ # K.I.T.T. Bike Light
2
+ #
2
3
# Use Button A to change color
3
4
# Use Button B to change style
4
- # Ride safe and don't Hassle the Hoff
5
- #
6
- # Created by Eric Gross. Sublime Text on MacBookPro on 5/27/19.
7
- # CodeCademy 2019: Hardware Programming with CircuitPython: BikeLight
8
-
9
-
5
+ # Use Slide Switch to power on/off
6
+ # Ride safe and don't hassle the Hoff
7
+ #
8
+ # Created by Eric Gross. Sublime Text on MacBook Pro (5/27/2019)
9
+ # Codecademy: Learn Hardware Programming with CircuitPython - Bike Light
10
10
11
11
from adafruit_circuitplayground .express import cpx
12
12
import time
13
13
14
14
colorIndex = 0
15
15
functionIndex = 0
16
- rainbow = ((255 , 0 , 0 ),(255 , 85 , 0 ),(255 , 255 , 0 ),(0 , 255 , 0 ),(34 , 139 , 34 ),(0 , 255 , 255 ),(0 , 0 , 255 ),(0 , 0 , 139 ),(255 , 0 , 255 ),(75 , 0 , 130 ),(0 ,0 ,0 ))
17
-
16
+ rainbow = ((255 , 0 , 0 ), (255 , 85 , 0 ), (255 , 255 , 0 ), (0 , 255 , 0 ), (34 , 139 , 34 ), (0 , 255 , 255 ), (0 , 0 , 255 ), (0 , 0 , 139 ), (255 , 0 , 255 ), (75 , 0 , 130 ), (0 ,0 ,0 ))
18
17
19
18
###### Function to Change Color ######
20
19
def checkPress (colorIndex ):
@@ -32,48 +31,46 @@ def functionPress(functionIndex):
32
31
return 0
33
32
return functionIndex
34
33
35
-
36
- ###### Color and Blinking #####
34
+ ###### Color and Blinking ######
37
35
def blinkLed (colorIndex , d = 0.5 , ledIndex = 10 , turnOff = True ):
38
36
if ledIndex == 10 :
39
- cpx .pixels .fill ((rainbow [colorIndex ][0 ],rainbow [colorIndex ][1 ],rainbow [colorIndex ][2 ]))
37
+ cpx .pixels .fill ((rainbow [colorIndex ][0 ], rainbow [colorIndex ][1 ], rainbow [colorIndex ][2 ]))
40
38
time .sleep (d )
41
39
else :
42
- cpx .pixels [ledIndex ] = (rainbow [colorIndex ][0 ],rainbow [colorIndex ][1 ],rainbow [colorIndex ][2 ])
40
+ cpx .pixels [ledIndex ] = (rainbow [colorIndex ][0 ], rainbow [colorIndex ][1 ], rainbow [colorIndex ][2 ])
43
41
time .sleep (d )
44
42
if turnOff == True :
45
- cpx .pixels .fill ((0 ,0 , 0 ))
43
+ cpx .pixels .fill ((0 , 0 , 0 ))
46
44
time .sleep (d )
47
45
return
48
46
49
-
50
47
def kitt (d = 0.1 ):
51
48
global colorIndex
52
49
colorIndex = checkPress (colorIndex )
53
- for x in range (0 ,10 ):
50
+ for x in range (0 , 10 ):
54
51
blinkLed (10 , d , x , False )
55
52
blinkLed (colorIndex , 0 , x , False )
56
53
time .sleep (d )
57
54
colorIndex = checkPress (colorIndex )
58
- for x in range (9 ,- 1 ,- 1 ):
55
+ for x in range (9 , - 1 , - 1 ):
59
56
blinkLed (10 , d , x , False )
60
57
blinkLed (colorIndex , 0 , x , False )
61
58
time .sleep (d )
62
59
return
63
60
64
61
def rainbowSpin (d = 0.1 ):
65
62
global colorIndex
66
- for x in range (0 ,10 ):
63
+ for x in range (0 , 10 ):
67
64
blinkLed (colorIndex , d , x , False )
68
65
colorIndex += 1
69
66
if colorIndex > 10 :
70
67
colorIndex = 0
71
68
return
72
69
73
-
74
70
##########################
75
71
###### Main Program ######
76
72
##########################
73
+
77
74
while True :
78
75
if cpx .switch :
79
76
functionIndex = functionPress (functionIndex )
@@ -86,4 +83,4 @@ def rainbowSpin(d = 0.1):
86
83
rainbowSpin ()
87
84
else :
88
85
# shut it
89
- cpx .pixels .fill ((0 , 0 , 0 ))
86
+ cpx .pixels .fill ((0 , 0 , 0 ))
0 commit comments