Skip to content

Commit bb2defd

Browse files
committed
Update kitt.py
1 parent 04a76dc commit bb2defd

File tree

1 file changed

+17
-20
lines changed
  • circuit-playground-part-1/bike-light

1 file changed

+17
-20
lines changed

circuit-playground-part-1/bike-light/kitt.py

100644100755
+17-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
# K.I.T.T. BikeLight
1+
# K.I.T.T. Bike Light
2+
#
23
# Use Button A to change color
34
# 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
1010

1111
from adafruit_circuitplayground.express import cpx
1212
import time
1313

1414
colorIndex = 0
1515
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))
1817

1918
###### Function to Change Color ######
2019
def checkPress(colorIndex):
@@ -32,48 +31,46 @@ def functionPress(functionIndex):
3231
return 0
3332
return functionIndex
3433

35-
36-
###### Color and Blinking #####
34+
###### Color and Blinking ######
3735
def blinkLed(colorIndex, d = 0.5, ledIndex = 10, turnOff = True):
3836
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]))
4038
time.sleep(d)
4139
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])
4341
time.sleep(d)
4442
if turnOff == True:
45-
cpx.pixels.fill((0,0,0))
43+
cpx.pixels.fill((0, 0, 0))
4644
time.sleep(d)
4745
return
4846

49-
5047
def kitt(d = 0.1):
5148
global colorIndex
5249
colorIndex = checkPress(colorIndex)
53-
for x in range(0,10):
50+
for x in range(0, 10):
5451
blinkLed(10, d, x, False)
5552
blinkLed(colorIndex, 0, x, False)
5653
time.sleep(d)
5754
colorIndex = checkPress(colorIndex)
58-
for x in range(9,-1,-1):
55+
for x in range(9, -1, -1):
5956
blinkLed(10, d, x, False)
6057
blinkLed(colorIndex, 0, x, False)
6158
time.sleep(d)
6259
return
6360

6461
def rainbowSpin(d = 0.1):
6562
global colorIndex
66-
for x in range(0,10):
63+
for x in range(0, 10):
6764
blinkLed(colorIndex, d, x, False)
6865
colorIndex += 1
6966
if colorIndex > 10:
7067
colorIndex = 0
7168
return
7269

73-
7470
##########################
7571
###### Main Program ######
7672
##########################
73+
7774
while True:
7875
if cpx.switch:
7976
functionIndex = functionPress(functionIndex)
@@ -86,4 +83,4 @@ def rainbowSpin(d = 0.1):
8683
rainbowSpin()
8784
else:
8885
# shut it
89-
cpx.pixels.fill((0, 0, 0))
86+
cpx.pixels.fill((0, 0, 0))

0 commit comments

Comments
 (0)