From c211e8d0cde98c855555c24da08bfe06274faa93 Mon Sep 17 00:00:00 2001 From: LordSyd Date: Tue, 26 Nov 2019 14:06:32 +0100 Subject: [PATCH 1/2] added dimfactor to blinkLed function added a factor to choose dimming in percent. makes it easier on the eyes while testing the code --- circuit-playground-part-1/bike-light/kitt.py | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/circuit-playground-part-1/bike-light/kitt.py b/circuit-playground-part-1/bike-light/kitt.py index 1ade256..d4e6219 100755 --- a/circuit-playground-part-1/bike-light/kitt.py +++ b/circuit-playground-part-1/bike-light/kitt.py @@ -32,17 +32,17 @@ def functionPress(functionIndex): return functionIndex ###### Color and Blinking ###### -def blinkLed(colorIndex, d = 0.5, ledIndex = 10, turnOff = True): - if ledIndex == 10: - cpx.pixels.fill((rainbow[colorIndex][0], rainbow[colorIndex][1], rainbow[colorIndex][2])) - time.sleep(d) - else: - cpx.pixels[ledIndex] = (rainbow[colorIndex][0], rainbow[colorIndex][1], rainbow[colorIndex][2]) - time.sleep(d) - if turnOff == True: - cpx.pixels.fill((0, 0, 0)) - time.sleep(d) - return +def blinkLed(colorIndex, d=0.5, ledIndex=10, turnOff=True, dimfactor=0.3#factor in percent): + if ledIndex == 10: + cpx.pixels.fill((int(rainbow[colorIndex][0] *dimfactor), int(rainbow[colorIndex][1]*dimfactor), int(rainbow[colorIndex][2]*dimfactor))) + time.sleep(d) + else: + cpx.pixels[ledIndex] = (int(rainbow[colorIndex][0]*dimfactor), int(rainbow[colorIndex][1]*dimfactor), int(rainbow[colorIndex][2]*dimfactor)) + time.sleep(d) + if turnOff: + cpx.pixels.fill((0, 0, 0)) + time.sleep(d) + return def kitt(d = 0.1): global colorIndex @@ -83,4 +83,4 @@ def rainbowSpin(d = 0.1): rainbowSpin() else: # shut it - cpx.pixels.fill((0, 0, 0)) \ No newline at end of file + cpx.pixels.fill((0, 0, 0)) From 48c342f87887adffb73afc9dac1c62337c7d02c6 Mon Sep 17 00:00:00 2001 From: LordSyd Date: Tue, 26 Nov 2019 19:47:25 +0100 Subject: [PATCH 2/2] fixed small typo typo at line 35 in comment, comment at wrong place --- circuit-playground-part-1/bike-light/kitt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuit-playground-part-1/bike-light/kitt.py b/circuit-playground-part-1/bike-light/kitt.py index d4e6219..a16711a 100755 --- a/circuit-playground-part-1/bike-light/kitt.py +++ b/circuit-playground-part-1/bike-light/kitt.py @@ -32,7 +32,7 @@ def functionPress(functionIndex): return functionIndex ###### Color and Blinking ###### -def blinkLed(colorIndex, d=0.5, ledIndex=10, turnOff=True, dimfactor=0.3#factor in percent): +def blinkLed(colorIndex, d=0.5, ledIndex=10, turnOff=True, dimfactor=0.3): #dimfactor in percent if ledIndex == 10: cpx.pixels.fill((int(rainbow[colorIndex][0] *dimfactor), int(rainbow[colorIndex][1]*dimfactor), int(rainbow[colorIndex][2]*dimfactor))) time.sleep(d)