Skip to content

Commit d00e7b6

Browse files
committed
change values, read encoder before check, print value
1 parent d071193 commit d00e7b6

File tree

1 file changed

+21
-19
lines changed
  • Rotary_Trinkey_Brightness_Crank

1 file changed

+21
-19
lines changed

Rotary_Trinkey_Brightness_Crank/code.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
# then brightness stays the same
2020
# if encoder value increases less than this
2121
# then brightness goes down
22-
STAY_EVEN_CHANGE_THRESHOLD = 50
22+
STAY_EVEN_CHANGE_THRESHOLD = 60
2323

2424
# if encoder value increases at least this much
2525
# then brightness goes up
26-
INCREASE_CHANGE_THRESHOLD = 85
26+
INCREASE_CHANGE_THRESHOLD = 95
2727

28-
# timestamp of last time an action occured
28+
# timestamp of last time an action occurred
2929
LAST_ACTION_TIME = 0
3030

3131
# encoder value variable
@@ -60,10 +60,27 @@
6060

6161
prev_switch_value = switch.value
6262

63+
# read current encoder value
64+
current_position = encoder.position
65+
position_change = int(current_position - last_position)
66+
67+
# positive change
68+
if position_change > 0:
69+
for _ in range(position_change):
70+
CUR_VALUE += position_change
71+
72+
# negative change
73+
elif position_change < 0:
74+
for _ in range(-position_change):
75+
# use absolute value to convert to positive
76+
CUR_VALUE += int(math.fabs(position_change))
77+
78+
last_position = current_position
79+
6380
if not PAUSED:
6481
# is it time for an action?
6582
if now > LAST_ACTION_TIME + ACTION_INTERVAL:
66-
# print(CUR_VALUE)
83+
print(CUR_VALUE)
6784

6885
# update previous time variable
6986
LAST_ACTION_TIME = now
@@ -85,19 +102,4 @@
85102
# reset encoder value
86103
CUR_VALUE = 0
87104

88-
# read current encoder value
89-
current_position = encoder.position
90-
position_change = int(current_position - last_position)
91-
92-
# positive change
93-
if position_change > 0:
94-
for _ in range(position_change):
95-
CUR_VALUE += position_change
96-
97-
# negative change
98-
elif position_change < 0:
99-
for _ in range(-position_change):
100-
# use absolute value to convert to positive
101-
CUR_VALUE += int(math.fabs(position_change))
102105

103-
last_position = current_position

0 commit comments

Comments
 (0)