Skip to content

Commit

Permalink
Update lesson_7.py
Browse files Browse the repository at this point in the history
************* Module lesson_7
lessons/lesson_7/lesson_7.py:89:0: C0301: Line too long (113/100) (line-too-long)
lessons/lesson_7/lesson_7.py:57:4: C0206: Consider iterating with .items() (consider-using-dict-items)
lessons/lesson_7/lesson_7.py:50:0: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
  • Loading branch information
ikostan committed May 9, 2024
1 parent 3faffed commit 9b25ef4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lessons/lesson_7/lesson_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
micropython using a potentiometer and the analog read function. This class is
for absolute beginners, and I do not assume you already understand the material
I am presenting. My goal is not to 'Show Off', but to genuinely teach you how
you can do this type of work and projects on your own. I will show all work step-by-step,
with clear instructions.
you can do this type of work and projects on your own. I will show all work
step-by-step, with clear instructions.
Enjoy!
"""

Expand Down Expand Up @@ -42,7 +42,7 @@ def all_led_off():
Turns all leds off
:return:
"""
for color in COLORS:
for color in COLORS.keys():
pin = Pin(Pins[color], Pin.OUT)
pin.value(0)

Expand All @@ -54,9 +54,14 @@ def value_to_color(v_value):
:param v_value:
:return:
"""
for color in COLORS:
new_color = ''

for color in COLORS.keys():
if v_value in COLORS[color]:
return color
new_color = color
break

return new_color


def turn_led_on(color):
Expand Down Expand Up @@ -86,7 +91,8 @@ def converter(read_value):
while True:
all_led_off() # Turn off all LEDs
v = potentiometer.read_u16() # Read potentiometer value -> v
value = converter(v) # Convert potentiometer value into integer between 0 and 100
# Convert potentiometer value into integer between 0 and 100
value = converter(v)
led_color = value_to_color(value) # Get color based on converted value
turn_led_on(led_color) # Turn ON corresponding LED
print(f'value: {value}, LED: {led_color}') # DEBUG output
Expand Down

0 comments on commit 9b25ef4

Please sign in to comment.