Added examples readme
This commit is contained in:
parent
44412365b8
commit
7cb12225ca
|
@ -0,0 +1,85 @@
|
|||
# Servo 2040 Examples <!-- omit in toc -->
|
||||
|
||||
- [Servo Examples](#servo-examples)
|
||||
- [Single Servo](#single-servo)
|
||||
- [Multiple Servos](#multiple-servos)
|
||||
- [Servo Cluster](#servo_cluster)
|
||||
- [Simple Easing](#simple-easing)
|
||||
- [Servo Wave](#servo-wave)
|
||||
- [Calibration](#calibration)
|
||||
- [Function Examples](#function-examples)
|
||||
- [Read Sensors](#read-sensors)
|
||||
- [Sensor Feedback](#sensor-feedback)
|
||||
- [Current Meter](#current-meter)
|
||||
- [LED Rainbow](#led-rainbow)
|
||||
- [Turn Off LEDs](#turn-off-leds)
|
||||
|
||||
|
||||
## Servo Examples
|
||||
|
||||
### Single Servo
|
||||
[single_servo.py](single_servo.py)
|
||||
|
||||
Demonstrates how to create a Servo object and control it.
|
||||
|
||||
|
||||
### Multiple Servos
|
||||
[multiple_servos.py](multiple_servos.py)
|
||||
|
||||
Demonstrates how to create multiple Servo objects and control them together.
|
||||
|
||||
|
||||
### Servo Cluster
|
||||
[servo_cluster.py](servo_cluster.py)
|
||||
|
||||
Demonstrates how to create a ServoCluster object to control multiple servos at once.
|
||||
|
||||
|
||||
### Simple Easing
|
||||
[simple_easing.py](simple_easing.py)
|
||||
|
||||
An example of how to move a servo smoothly between random positions.
|
||||
|
||||
|
||||
### Servo Wave
|
||||
[servo_wave.py](servo_wave.py)
|
||||
|
||||
An example of applying a wave pattern to a group of servos and the LEDs.
|
||||
|
||||
|
||||
### Calibration
|
||||
[calibration.py](calibration.py)
|
||||
|
||||
Shows how to create servos with different common calibrations, modify a servo's existing calibration, and create a servo with a custom calibration.
|
||||
|
||||
|
||||
## Function Examples
|
||||
|
||||
### Read Sensors
|
||||
[read_sensors.py](read_sensors.py)
|
||||
|
||||
Shows how to initialise and read the 6 external and 2 internal sensors of Servo 2040.
|
||||
|
||||
|
||||
### Sensor Feedback
|
||||
[sensor_feedback.py](sensor_feedback.py)
|
||||
|
||||
Show how to read the 6 external sensors and display their values on the neighbouring LEDs.
|
||||
|
||||
|
||||
### Current Meter
|
||||
[current_meter.py](current_meter.py)
|
||||
|
||||
An example of how to use Servo 2040's current measuring ability and display the value on the onboard LED bar.
|
||||
|
||||
|
||||
### LED Rainbow
|
||||
[led_rainbow.py](led_rainbow.py)
|
||||
|
||||
Displays a rotating rainbow pattern on the Servo 2040's onboard LED bar.
|
||||
|
||||
|
||||
### Turn Off LEDs
|
||||
[turn_off_leds.py](turn_off_leds.py)
|
||||
|
||||
A simple program that turns off the onboard LED bar.
|
|
@ -1,9 +1,14 @@
|
|||
from servo import Calibration, Servo, servo2040, ANGULAR, LINEAR, CONTINUOUS
|
||||
|
||||
# --------------------------------------------------
|
||||
# An example of how to create and modify
|
||||
# the calibration of an angular servo
|
||||
# --------------------------------------------------
|
||||
"""
|
||||
Shows how to create servos with different common
|
||||
calibrations, modify a servo's existing calibration,
|
||||
and create a servo with a custom calibration.
|
||||
"""
|
||||
|
||||
# -----------------------------------------------------
|
||||
# Create and modify the calibration of an angular servo
|
||||
# -----------------------------------------------------
|
||||
|
||||
# Create an angular servo on pin 0. By default its value ranges from -90 to +90
|
||||
angular_servo = Servo(servo2040.SERVO_1, ANGULAR)
|
||||
|
@ -24,10 +29,9 @@ angular_servo.calibration(cal)
|
|||
print("Wide Angle Servo:", angular_servo.calibration(), end="\n\n")
|
||||
|
||||
|
||||
# --------------------------------------------------
|
||||
# An example of how to create and modify
|
||||
# the calibration of a linear servo
|
||||
# --------------------------------------------------
|
||||
# ---------------------------------------------------
|
||||
# Create and modify the calibration of a linear servo
|
||||
# ---------------------------------------------------
|
||||
|
||||
LINEAR_RANGE = 50 # The range we want the linear servo to cover
|
||||
|
||||
|
@ -43,10 +47,9 @@ linear_servo.calibration(cal)
|
|||
print("Linear Servo:", linear_servo.calibration(), end="\n\n")
|
||||
|
||||
|
||||
# --------------------------------------------------
|
||||
# An example of how to create and modify the
|
||||
# calibration of a continuous rotation servo
|
||||
# --------------------------------------------------
|
||||
# ----------------------------------------------------------------
|
||||
# Create and modify the calibration of a continuous rotation servo
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
CONTINUOUS_SPEED = 10 # The speed we want the continuous servo to cover
|
||||
|
||||
|
@ -63,10 +66,9 @@ continuous_servo.calibration(cal)
|
|||
print("Continuous Servo:", continuous_servo.calibration(), end="\n\n")
|
||||
|
||||
|
||||
# --------------------------------------------------
|
||||
# An example of how to create a custom
|
||||
# calibration and build a servo using it
|
||||
# --------------------------------------------------
|
||||
# ------------------------------------------------------
|
||||
# Create a custom calibration and build a servo using it
|
||||
# ------------------------------------------------------
|
||||
|
||||
# Create an empty calibration
|
||||
cal = Calibration()
|
||||
|
|
|
@ -4,13 +4,16 @@ from pimoroni import Analog, AnalogMux, Button
|
|||
from plasma import WS2812
|
||||
from servo import ServoCluster, servo2040
|
||||
|
||||
# NOTE: ServoCluster lets you control up to 30 servos at once. This is
|
||||
# done using the RP2040's PIO system. As such it is experimental and may
|
||||
# have edge-cases that will need to be fixed. This is particularly true
|
||||
# when attempting to run a program multiple times.
|
||||
# If you do encounter issues, try resetting your board.
|
||||
"""
|
||||
An example of how to use Servo 2040's current measuring
|
||||
ability and display the value on the onboard LED bar.
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
Press "Boot" to exit the program.
|
||||
|
||||
NOTE: ServoCluster and Plasma WS2812 use the RP2040's PIO system,
|
||||
and as such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
BRIGHTNESS = 0.4 # The brightness of the LEDs
|
||||
UPDATES = 50 # How many times to update LEDs and Servos per second
|
||||
|
|
|
@ -3,7 +3,15 @@ from pimoroni import Button
|
|||
from plasma import WS2812
|
||||
from servo import servo2040
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
"""
|
||||
Displays a rotating rainbow pattern on the Servo 2040's onboard LED bar.
|
||||
|
||||
Press "Boot" to exit the program.
|
||||
|
||||
NOTE: Plasma WS2812 uses the RP2040's PIO system, and as
|
||||
such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
SPEED = 5 # The speed that the LEDs will cycle at
|
||||
BRIGHTNESS = 0.4 # The brightness of the LEDs
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
from plasma import WS2812
|
||||
from servo import servo2040
|
||||
|
||||
# Create the LED bar, using PIO 1 and State Machine 0
|
||||
led_bar = WS2812(servo2040.NUM_LEDS, 1, 0, servo2040.LED_DAT)
|
||||
|
||||
# Start updating the LED bar
|
||||
led_bar.start()
|
|
@ -2,6 +2,10 @@ import time
|
|||
import math
|
||||
from servo import Servo, servo2040
|
||||
|
||||
"""
|
||||
Demonstrates how to create multiple Servo objects and control them together.
|
||||
"""
|
||||
|
||||
# Create a list of servos for pins 0 to 3. Up to 16 servos can be created
|
||||
START_PIN = servo2040.SERVO_1
|
||||
END_PIN = servo2040.SERVO_3
|
||||
|
|
|
@ -3,7 +3,12 @@ from machine import Pin
|
|||
from pimoroni import Analog, AnalogMux, Button
|
||||
from servo import servo2040
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
"""
|
||||
Shows how to initialise and read the 6 external
|
||||
and 2 internal sensors of Servo 2040.
|
||||
|
||||
Press "Boot" to exit the program.
|
||||
"""
|
||||
|
||||
# Create the user button
|
||||
user_sw = Button(servo2040.USER_SW)
|
||||
|
|
|
@ -4,7 +4,16 @@ from pimoroni import Analog, AnalogMux, Button
|
|||
from plasma import WS2812
|
||||
from servo import servo2040
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
"""
|
||||
Show how to read the 6 external sensors and
|
||||
display their values on the neighbouring LEDs.
|
||||
|
||||
Press "Boot" to exit the program.
|
||||
|
||||
NOTE: Plasma WS2812 uses the RP2040's PIO system, and as
|
||||
such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
BRIGHTNESS = 0.4 # The brightness of the LEDs
|
||||
UPDATES = 50 # How many times to update LEDs and Servos per second
|
||||
|
|
|
@ -2,11 +2,13 @@ import time
|
|||
import math
|
||||
from servo import ServoCluster, servo2040
|
||||
|
||||
# NOTE: ServoCluster lets you control up to 30 servos at once. This is
|
||||
# done using the RP2040's PIO system. As such it is experimental and may
|
||||
# have edge-cases that will need to be fixed. This is particularly true
|
||||
# when attempting to run a program multiple times.
|
||||
# If you do encounter issues, try resetting your board.
|
||||
"""
|
||||
Demonstrates how to create a ServoCluster object to control multiple servos at once.
|
||||
|
||||
NOTE: ServoCluster uses the RP2040's PIO system, and as
|
||||
such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
# Create a servo cluster for pins 0 to 3, using PIO 0 and State Machine 0
|
||||
START_PIN = servo2040.SERVO_1
|
||||
|
|
|
@ -4,13 +4,15 @@ from pimoroni import Button
|
|||
from plasma import WS2812
|
||||
from servo import ServoCluster, servo2040
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
"""
|
||||
An example of applying a wave pattern to a group of servos and the LEDs.
|
||||
|
||||
# NOTE: ServoCluster lets you control up to 30 servos at once. This is
|
||||
# done using the RP2040's PIO system. As such it is experimental and may
|
||||
# have edge-cases that will need to be fixed. This is particularly true
|
||||
# when attempting to run a program multiple times.
|
||||
# If you do encounter issues, try resetting your board.
|
||||
Press "Boot" to exit the program.
|
||||
|
||||
NOTE: ServoCluster and Plasma WS2812 use the RP2040's PIO system,
|
||||
and as such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
SPEED = 5 # The speed that the LEDs will cycle at
|
||||
BRIGHTNESS = 0.4 # The brightness of the LEDs
|
|
@ -4,7 +4,11 @@ import random
|
|||
from pimoroni import Button
|
||||
from servo import Servo, servo2040
|
||||
|
||||
# Press "Boot" to exit the program.
|
||||
"""
|
||||
An example of how to move a servo smoothly between random positions.
|
||||
|
||||
Press "Boot" to exit the program.
|
||||
"""
|
||||
|
||||
UPDATES = 50 # How many times to update Servos per second
|
||||
TIME_FOR_EACH_MOVE = 2 # The time to travel between each random value
|
||||
|
|
|
@ -2,6 +2,10 @@ import time
|
|||
import math
|
||||
from servo import Servo, servo2040
|
||||
|
||||
"""
|
||||
Demonstrates how to create a Servo object and control it.
|
||||
"""
|
||||
|
||||
# Create a servo on pin 0
|
||||
s = Servo(servo2040.SERVO_1)
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
from plasma import WS2812
|
||||
from servo import servo2040
|
||||
|
||||
"""
|
||||
A simple program that turns off the onboard LED bar.
|
||||
|
||||
Press "Boot" to exit the program.
|
||||
|
||||
NOTE: Plasma WS2812 uses the RP2040's PIO system, and as
|
||||
such may have problems when running code multiple times.
|
||||
If you encounter issues, try resetting your board.
|
||||
"""
|
||||
|
||||
# Create the LED bar, using PIO 1 and State Machine 0
|
||||
led_bar = WS2812(servo2040.NUM_LEDS, 1, 0, servo2040.LED_DAT)
|
||||
|
||||
# Start updating the LED bar
|
||||
led_bar.start()
|
Loading…
Reference in New Issue