|
| 1 | +# two_sequences_at_once_led.py |
| 2 | +# |
| 3 | +# an example of how to use two sequences at the same time without blocking either one |
| 4 | +# |
1 | 5 | import board |
2 | 6 | import digitalio |
3 | 7 | import pwmio |
|
18 | 22 | # init_position = initial start position |
19 | 23 | # result = float, int |
20 | 24 | vs1 = Vspeed(init_position=MIN, result="int") |
21 | | -# make the output of the function be within the bounds set |
22 | | -vs1.set_bounds(lower_bound=MIN, upper_bound=max) |
23 | 25 | vs2 = Vspeed(init_position=MAX, result="int") |
24 | | -vs2.set_bounds(lower_bound=MIN, upper_bound=max) |
| 26 | +# make the output of the function be within the bounds set |
| 27 | +vs1.set_bounds(lower_bound=MIN, upper_bound=MAX) |
| 28 | +vs2.set_bounds(lower_bound=MIN, upper_bound=MAX) |
25 | 29 |
|
26 | 30 | # set the LED to a known starting point |
27 | 31 | led1.duty_cycle = vs1.position |
28 | 32 | led2.duty_cycle = vs2.position |
29 | 33 |
|
30 | | -my_sequence1 = [(MIN, 1, 100, "QuadEaseIn"), |
31 | | - (MAX, 1, 100, "QuadEaseOut")] |
| 34 | +my_sequence1 = [(MIN, 1.0, 10, "QuadEaseIn"), |
| 35 | + (MAX, 1.0, 10, "QuadEaseOut")] |
32 | 36 |
|
33 | | -my_sequence2 = [(MAX, 1, 100, "QuadEaseOut"), |
34 | | - (MIN, 1, 100, "QuadEaseIn")] |
| 37 | +my_sequence2 = [(MAX, 1.0, 10, "QuadEaseOut"), |
| 38 | + (MIN, 1.0, 10, "SineEaseInOut")] |
35 | 39 |
|
36 | 40 | running1 = True |
37 | 41 | running2 = True |
|
50 | 54 | if changed1: |
51 | 55 | #print(f'Sequence Num: {vs1.seq_pos}, Step: {vs1.step}, Position: {position1}') |
52 | 56 | led1.duty_cycle = position1 |
53 | | - position2, running2, changed2 = vs2.sequence( |
| 57 | + |
| 58 | + position2, running2, changed2 = vs2.sequence( |
54 | 59 | sequence=my_sequence2, loop_max=0) |
55 | 60 |
|
56 | 61 | if changed2: |
|
0 commit comments