Skip to content

Adding multi-servo examples #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/servokit_all_servos_sequential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Example that iterates through a servo on every channel, sets each to 180 and then back to 0."""
import time
from adafruit_servokit import ServoKit

# Set channels to the number of servo channels on your kit.
# 8 for FeatherWing, 16 for Shield/HAT/Bonnet.
kit = ServoKit(channels=8)

# Change range to the number of servos connected.
# They must be on channels within the specified range!
for i in range(8):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use range(len(kit.servo)) here? Then you can drop the warning note...

https://github.com/adafruit/Adafruit_CircuitPython_ServoKit/blob/master/adafruit_servokit.py#L157

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sommersoft The suggestion works! However, only makes sense if you're working with the exact number of servos as there are channels on the board. So if you connect 4, and say range(len(kit.servo)) it'll work, but it's sending data to unused channels.

Maybe it doesn't matter?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it doesn't matter?

It shouldn't, except to add time to overall loop.

Like I said, its an option, but guards against any out of range occurrences. If you'd rather leave it as is, that's ok too.

kit.servo[i].angle = 180
time.sleep(1)
kit.servo[i].angle = 0
time.sleep(1)
16 changes: 16 additions & 0 deletions examples/servokit_all_servos_synchronised.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Example that rotates servos on every channel to 180 and then back to 0."""
import time
from adafruit_servokit import ServoKit

# Set channels to the number of servo channels on your kit.
# 8 for FeatherWing, 16 for Shield/HAT/Bonnet.
kit = ServoKit(channels=8)

# Change range to the number of servos connected.
# They must be on channels within the specified range!
for i in range(8):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above...

kit.servo[i].angle = 180
time.sleep(1)
for i in range(8):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once more for good measure? 😄

kit.servo[i].angle = 0
time.sleep(1)