Skip to content

Commit f5a050f

Browse files
author
Philip van Allen
committed
fixed bugs and comments
1 parent 8e25a05 commit f5a050f

8 files changed

+74
-30
lines changed

examples/move_simple.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# move_simple.py
2+
#
3+
# a non-hardware dependant example of using the VarSpeedPython class
4+
# to ramp a value from one value to another
5+
#
16
import time
27

38
from varspeed import Vspeed

examples/move_simple_led.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# move_simple_led.py
2+
#
3+
# changes the brightness of an LED over time
4+
15
import board
26
import digitalio
37
import pwmio
@@ -18,12 +22,22 @@
1822
# LED setup for most CircuitPython boards:
1923
led = pwmio.PWMOut(board.D2, frequency=5000, duty_cycle=0)
2024

25+
print(f'Paused for 5 seconds at {MIN}...')
26+
# set the servo to a known starting point
27+
led.duty_cycle = MIN
28+
time.sleep(5)
29+
30+
print(f'Moving to {MIN}...')
31+
2132
running = True
2233
while running:
2334
# run a move from the current position
2435
# move(new_position,time_secs of move,steps in move,easing function)
2536
position, running, changed = vs.move(
26-
new_position=MAX, time_secs=2, steps=100, easing="QuadEaseInOut")
37+
new_position=MAX, time_secs=5, steps=100, easing="QuadEaseInOut")
2738
if changed:
2839
print(f'Step: {vs.step}, Position: {position}')
29-
led.duty_cycle = int(position / 100)
40+
led.duty_cycle = int(position)
41+
42+
print(f'Paused for 5 seconds at {position}...')
43+
time.sleep(5)

examples/move_simple_servo.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# move_simple_servo.py
2+
#
3+
# changes the position of a servo over time
4+
#
15
import time
26
import board
37
import pwmio
@@ -11,7 +15,7 @@
1115
#
1216
# init_position = initial start position
1317
# result = float, int
14-
vs = Vspeed(init_position=max, result="int")
18+
vs = Vspeed(init_position=MIN, result="int")
1519
# make the output of the function be within the bounds set
1620
vs.set_bounds(lower_bound=MIN, upper_bound=MAX)
1721

@@ -21,13 +25,12 @@
2125
# Create a servo object
2226
my_servo = servo.Servo(pwm)
2327

28+
print(f'Paused for 5 seconds at {MIN}...')
2429
# set the servo to a known starting point
25-
my_servo.angle = vs.position
26-
27-
print(f'Paused at {vs.position}...')
30+
my_servo.angle = MIN
2831
time.sleep(5)
2932

30-
print(f'Moving to {min}...')
33+
print(f'Moving to {MIN}...')
3134
running = True
3235
while running:
3336
# move(new_position,time_secs of move,steps in move,easing function)

examples/sequence_simple.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# sequence_simple.py
2+
#
3+
# a non-hardware dependant example of using the VarSpeedPython class
4+
# to have a series of moves in a sequence
5+
#
16
import time
27

38
from varspeed import Vspeed
@@ -9,13 +14,13 @@
914
#
1015
# init_position = initial start position
1116
# result = float, int
12-
vs = Vspeed(init_position=max, result="int")
17+
vs = Vspeed(init_position=MAX, result="int")
1318
# make the output of the function be within the bounds set
1419
vs.set_bounds(lower_bound=MIN, upper_bound=MAX)
1520

1621
my_sequence = [(MAX / 2, 2, 10, "QuadEaseIn"),
17-
(MAX, 0.5, 9, "QuadEaseOut"),
18-
(MIN, 0.5, 8, "SineEaseInOut")]
22+
(MIN, 2.0, 10, "QuadEaseOut"),
23+
(MAX, 2.0, 10, "SineEaseInOut")]
1924

2025
running = True
2126
#print("starting position",vs.position)

examples/sequence_simple_servo.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# sequence_simple_servo.py
2+
#
3+
# an example of using the VarSpeedPython class to have a series of moves in a sequence
4+
#
15
import time
26
import board
37
import pwmio
@@ -11,9 +15,9 @@
1115
#
1216
# init_position = initial start position
1317
# result = float, int
14-
vs = Vspeed(init_position=MAX, result="int")
18+
vs = Vspeed(init_position=MIN, result="int")
1519
# make the output of the function be within the bounds set
16-
vs.set_bounds(lower_bound=min, upper_bound=max)
20+
vs.set_bounds(lower_bound=MIN, upper_bound=MAX)
1721

1822
# create a PWMOut object on Pin D2.
1923
pwm = pwmio.PWMOut(board.D2, duty_cycle=2 ** 15, frequency=50)
@@ -22,11 +26,11 @@
2226
my_servo = servo.Servo(pwm)
2327

2428
# set the servo to a known starting point
25-
my_servo.angle = vs.position
29+
my_servo.angle = MIN
2630

2731
my_sequence = [(MAX / 2, 2, 10, "QuadEaseIn"),
28-
(MAX, 0.5, 9, "QuadEaseOut"),
29-
(MIN, 0.5, 8, "SineEaseInOut")]
32+
(MIN, 2.0, 10, "QuadEaseOut"),
33+
(MAX, 2.0, 10, "SineEaseInOut")]
3034

3135
running = True
3236
while running:
@@ -39,7 +43,7 @@
3943
# if 1, play once
4044
# if >1, loop sequence that many times
4145
#
42-
position, running, changed = vs.sequence(sequence=my_sequence, loop_max=1)
46+
position, running, changed = vs.sequence(sequence=my_sequence, loop_max=2)
4347

4448
#print(position, running, changed)
4549
if changed:

examples/two_sequences_at_once.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# two_sequences_at_once.py
2+
#
3+
# runs two sequences in parallel without interfering with each another
4+
#
15
import time
26

37
from varspeed import Vspeed
@@ -13,11 +17,11 @@
1317
vs2 = Vspeed(init_position=MAX, result="int")
1418

1519
# create the sequences
16-
my_sequence1 = [(0, 0.5, 10, "QuadEaseIn"),
17-
(180, 0.5, 10, "QuadEaseOut")]
20+
my_sequence1 = [(MIN, 1.0, 10, "QuadEaseIn"),
21+
(MAX, 1.0, 10, "QuadEaseOut")]
1822

19-
my_sequence2 = [(180, 0.5, 10, "QuadEaseOut"),
20-
(0, 0.5, 10, "SineEaseInOut")]
23+
my_sequence2 = [(MAX, 1.0, 10, "QuadEaseOut"),
24+
(MIN, 1.0, 10, "SineEaseInOut")]
2125

2226
running1 = True
2327
running2 = True

examples/two_sequences_at_once_led.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
#
15
import board
26
import digitalio
37
import pwmio
@@ -18,20 +22,20 @@
1822
# init_position = initial start position
1923
# result = float, int
2024
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)
2325
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)
2529

2630
# set the LED to a known starting point
2731
led1.duty_cycle = vs1.position
2832
led2.duty_cycle = vs2.position
2933

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")]
3236

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")]
3539

3640
running1 = True
3741
running2 = True
@@ -50,7 +54,8 @@
5054
if changed1:
5155
#print(f'Sequence Num: {vs1.seq_pos}, Step: {vs1.step}, Position: {position1}')
5256
led1.duty_cycle = position1
53-
position2, running2, changed2 = vs2.sequence(
57+
58+
position2, running2, changed2 = vs2.sequence(
5459
sequence=my_sequence2, loop_max=0)
5560

5661
if changed2:

examples/two_sequences_at_once_servo.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# two_sequences_at_once_servo.py
2+
#
3+
# an example of how to use two sequences at the same time without blocking either one
4+
#
15
import time
26
import board
37
import pwmio
@@ -22,9 +26,9 @@
2226
# result = float, int
2327
vs1 = Vspeed(init_position=MIN, result="int")
2428
# make the output of the function be within the bounds set
25-
vs1.set_bounds(lower_bound=MIN, upper_bound=max)
29+
vs1.set_bounds(lower_bound=MIN, upper_bound=MAX)
2630
vs2 = Vspeed(init_position=MAX, result="int")
27-
vs2.set_bounds(lower_bound=MIN, upper_bound=max)
31+
vs2.set_bounds(lower_bound=MIN, upper_bound=MAX)
2832

2933
# set the servo to a known starting point
3034
my_servo1.angle = vs1.position

0 commit comments

Comments
 (0)