|
19 | 19 | # then brightness stays the same |
20 | 20 | # if encoder value increases less than this |
21 | 21 | # then brightness goes down |
22 | | -STAY_EVEN_CHANGE_THRESHOLD = 50 |
| 22 | +STAY_EVEN_CHANGE_THRESHOLD = 60 |
23 | 23 |
|
24 | 24 | # if encoder value increases at least this much |
25 | 25 | # then brightness goes up |
26 | | -INCREASE_CHANGE_THRESHOLD = 85 |
| 26 | +INCREASE_CHANGE_THRESHOLD = 95 |
27 | 27 |
|
28 | | -# timestamp of last time an action occured |
| 28 | +# timestamp of last time an action occurred |
29 | 29 | LAST_ACTION_TIME = 0 |
30 | 30 |
|
31 | 31 | # encoder value variable |
|
60 | 60 |
|
61 | 61 | prev_switch_value = switch.value |
62 | 62 |
|
| 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 | + |
63 | 80 | if not PAUSED: |
64 | 81 | # is it time for an action? |
65 | 82 | if now > LAST_ACTION_TIME + ACTION_INTERVAL: |
66 | | - # print(CUR_VALUE) |
| 83 | + print(CUR_VALUE) |
67 | 84 |
|
68 | 85 | # update previous time variable |
69 | 86 | LAST_ACTION_TIME = now |
|
85 | 102 | # reset encoder value |
86 | 103 | CUR_VALUE = 0 |
87 | 104 |
|
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)) |
102 | 105 |
|
103 | | - last_position = current_position |
|
0 commit comments