a
This commit is contained in:
581
PCA9685GpioExample.java
Normal file
581
PCA9685GpioExample.java
Normal file
File diff suppressed because one or more lines are too long
BIN
__pycache__/threading.cpython-39.pyc
Normal file
BIN
__pycache__/threading.cpython-39.pyc
Normal file
Binary file not shown.
55
simpletest.py
Executable file
55
simpletest.py
Executable file
@@ -0,0 +1,55 @@
|
|||||||
|
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||||
|
# This will move channel 0 from min to max position repeatedly.
|
||||||
|
# Author: Tony DiCola
|
||||||
|
# License: Public Domain
|
||||||
|
from __future__ import division
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Import the PCA9685 module.
|
||||||
|
import Adafruit_PCA9685
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment to enable debug output.
|
||||||
|
#import logging
|
||||||
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
# Initialise the PCA9685 using the default address (0x40).
|
||||||
|
pwm = Adafruit_PCA9685.PCA9685()
|
||||||
|
|
||||||
|
# Alternatively specify a different address and/or bus:
|
||||||
|
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||||
|
|
||||||
|
# Configure min and max servo pulse lengths
|
||||||
|
servo_min = 150 # Min pulse length out of 4096
|
||||||
|
servo_max = 400 # Max pulse length out of 4096
|
||||||
|
|
||||||
|
# Helper function to make setting a servo pulse width simpler.
|
||||||
|
def set_servo_pulse(channel, pulse):
|
||||||
|
pulse_length = 1000000 # 1,000,000 us per second
|
||||||
|
pulse_length //= 60 # 60 Hz
|
||||||
|
print('{0}us per period'.format(pulse_length))
|
||||||
|
pulse_length //= 4096 # 12 bits of resolution
|
||||||
|
print('{0}us per bit'.format(pulse_length))
|
||||||
|
pulse *= 1000
|
||||||
|
pulse //= pulse_length
|
||||||
|
pwm.set_pwm(channel, 0, pulse)
|
||||||
|
|
||||||
|
# Set frequency to 60hz, good for servos.
|
||||||
|
pwm.set_pwm_freq(60)
|
||||||
|
|
||||||
|
print('Moving servo on channel 0, press Ctrl-C to quit...')
|
||||||
|
while True:
|
||||||
|
# Move servo on channel O between extremes.
|
||||||
|
pwm.set_pwm(0, 0, servo_min)
|
||||||
|
pwm.set_pwm(1, 0, servo_min)
|
||||||
|
pwm.set_pwm(2, 0, servo_min)
|
||||||
|
pwm.set_pwm(3, 0, servo_min)
|
||||||
|
pwm.set_pwm(4, 0, servo_min)
|
||||||
|
time.sleep(1)
|
||||||
|
pwm.set_pwm(0, 0, servo_max)
|
||||||
|
pwm.set_pwm(1, 0, servo_max)
|
||||||
|
pwm.set_pwm(2, 0, servo_max)
|
||||||
|
pwm.set_pwm(3, 0, servo_max)
|
||||||
|
pwm.set_pwm(4, 0, servo_max)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
53
simpletest2.py
Executable file
53
simpletest2.py
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||||
|
# This will move channel 0 from min to max position repeatedly.
|
||||||
|
# Author: Tony DiCola
|
||||||
|
# License: Public Domain
|
||||||
|
from __future__ import division
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Import the PCA9685 module.
|
||||||
|
import Adafruit_PCA9685
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment to enable debug output.
|
||||||
|
#import logging
|
||||||
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
# Initialise the PCA9685 using the default address (0x40).
|
||||||
|
pwm = Adafruit_PCA9685.PCA9685()
|
||||||
|
|
||||||
|
# Alternatively specify a different address and/or bus:
|
||||||
|
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||||
|
|
||||||
|
# Configure min and max servo pulse lengths
|
||||||
|
servo_min = 150 # Min pulse length out of 4096
|
||||||
|
servo_max = 400 # Max pulse length out of 4096
|
||||||
|
|
||||||
|
# Helper function to make setting a servo pulse width simpler.
|
||||||
|
def set_servo_pulse(channel, pulse):
|
||||||
|
pulse_length = 1000000 # 1,000,000 us per second
|
||||||
|
pulse_length //= 60 # 60 Hz
|
||||||
|
print('{0}us per period'.format(pulse_length))
|
||||||
|
pulse_length //= 4096 # 12 bits of resolution
|
||||||
|
print('{0}us per bit'.format(pulse_length))
|
||||||
|
pulse *= 1000
|
||||||
|
pulse //= pulse_length
|
||||||
|
pwm.set_pwm(channel, 0, pulse)
|
||||||
|
|
||||||
|
# Set frequency to 60hz, good for servos.
|
||||||
|
pwm.set_pwm_freq(60)
|
||||||
|
|
||||||
|
print('Moving servo on channel 4, press Ctrl-C to quit...')
|
||||||
|
while True:
|
||||||
|
|
||||||
|
for x in range(6):
|
||||||
|
pwm.set_pwm(x, 0,150)
|
||||||
|
|
||||||
|
print('200')
|
||||||
|
time.sleep(1)
|
||||||
|
for y in range(6):
|
||||||
|
pwm.set_pwm(y, 0, 400)
|
||||||
|
|
||||||
|
print('350')
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
46
simpletest3.py
Executable file
46
simpletest3.py
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||||
|
# This will move channel 0 from min to max position repeatedly.
|
||||||
|
# Author: Tony DiCola
|
||||||
|
# License: Public Domain
|
||||||
|
from __future__ import division
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Import the PCA9685 module.
|
||||||
|
import Adafruit_PCA9685
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment to enable debug output.
|
||||||
|
#import logging
|
||||||
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
# Initialise the PCA9685 using the default address (0x40).
|
||||||
|
pwm = Adafruit_PCA9685.PCA9685()
|
||||||
|
|
||||||
|
# Alternatively specify a different address and/or bus:
|
||||||
|
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||||
|
|
||||||
|
# Configure min and max servo pulse lengths
|
||||||
|
servo_min = 150 # Min pulse length out of 4096
|
||||||
|
servo_max = 600 # Max pulse length out of 4096
|
||||||
|
|
||||||
|
# Helper function to make setting a servo pulse width simpler.
|
||||||
|
def set_servo_pulse(channel, pulse):
|
||||||
|
pulse_length = 1000000 # 1,000,000 us per second
|
||||||
|
pulse_length //= 60 # 60 Hz
|
||||||
|
print('{0}us per period'.format(pulse_length))
|
||||||
|
pulse_length //= 4096 # 12 bits of resolution
|
||||||
|
print('{0}us per bit'.format(pulse_length))
|
||||||
|
pulse *= 1000
|
||||||
|
pulse //= pulse_length
|
||||||
|
pwm.set_pwm(channel, 0, pulse)
|
||||||
|
|
||||||
|
# Set frequency to 60hz, good for servos.
|
||||||
|
pwm.set_pwm_freq(60)
|
||||||
|
|
||||||
|
print('Moving servo on channel 4, press Ctrl-C to quit...')
|
||||||
|
while True:
|
||||||
|
|
||||||
|
channel = int(input("Channel:\n"))
|
||||||
|
pos = int(input("Position: \n"))
|
||||||
|
num = int(input("num \n"))
|
||||||
|
pwm.set_pwm(channel, 0,pos)
|
||||||
49
testwalk.py
Executable file
49
testwalk.py
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
# Simple demo of of the PCA9685 PWM servo/LED controller library.
|
||||||
|
# This will move channel 0 from min to max position repeatedly.
|
||||||
|
# Author: Tony DiCola
|
||||||
|
# License: Public Domain
|
||||||
|
from __future__ import division
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Import the PCA9685 module.
|
||||||
|
import Adafruit_PCA9685
|
||||||
|
|
||||||
|
|
||||||
|
# Uncomment to enable debug output.
|
||||||
|
#import logging
|
||||||
|
#logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
# Initialise the PCA9685 using the default address (0x40).
|
||||||
|
pwm = Adafruit_PCA9685.PCA9685()
|
||||||
|
|
||||||
|
# Alternatively specify a different address and/or bus:
|
||||||
|
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
|
||||||
|
|
||||||
|
# Configure min and max servo pulse lengths
|
||||||
|
servo_min = 150 # Min pulse length out of 4096
|
||||||
|
servo_max = 400 # Max pulse length out of 4096
|
||||||
|
|
||||||
|
# Helper function to make setting a servo pulse width simpler.
|
||||||
|
def set_servo_pulse(channel, pulse):
|
||||||
|
pulse_length = 1000000 # 1,000,000 us per second
|
||||||
|
pulse_length //= 60 # 60 Hz
|
||||||
|
print('{0}us per period'.format(pulse_length))
|
||||||
|
pulse_length //= 4096 # 12 bits of resolution
|
||||||
|
print('{0}us per bit'.format(pulse_length))
|
||||||
|
pulse *= 1000
|
||||||
|
pulse //= pulse_length
|
||||||
|
pwm.set_pwm(channel, 0, pulse)
|
||||||
|
|
||||||
|
# Set frequency to 60hz, good for servos.
|
||||||
|
pwm.set_pwm_freq(60)
|
||||||
|
|
||||||
|
print('Moving servo on channel 0, press Ctrl-C to quit...')
|
||||||
|
while True:
|
||||||
|
pwm.set_pwm(6,0,150)
|
||||||
|
for x in range(150,400):
|
||||||
|
print (x)
|
||||||
|
pwm.set_pwm(6, 0, x)
|
||||||
|
math = round(0.026*pow((x-275),2))
|
||||||
|
print (math)
|
||||||
|
pwm.set_pwm(0, 0, math)
|
||||||
|
|
||||||
20
testwalk2.py
Normal file
20
testwalk2.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""Simple test for a standard servo on channel 0 and a continuous rotation servo on channel 1."""
|
||||||
|
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=16)
|
||||||
|
kit.servo[12].set_pulse_width_range(1000, 2000)
|
||||||
|
#kit.servo[12].angle = 180
|
||||||
|
#time.sleep(1)
|
||||||
|
kit.continuous_servo[12].throttle = 1
|
||||||
|
time.sleep(3)
|
||||||
|
kit.continuous_servo[12].throttle = -1
|
||||||
|
time.sleep(3)
|
||||||
|
kit.servo[0].angle = 0
|
||||||
|
kit.continuous_servo[12].throttle = 0
|
||||||
11
testwalk3.py
Normal file
11
testwalk3.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import time
|
||||||
|
from adafruit_servokit import ServoKit
|
||||||
|
|
||||||
|
kit = ServoKit(channels=16)
|
||||||
|
kit.servo[12].set_pulse_width_range(1000, 2000)
|
||||||
|
|
||||||
|
kit.servo[12].actuation_range = 200
|
||||||
|
while True:
|
||||||
|
channel = int(input("Channel:\n"))
|
||||||
|
pos = int(input("Position: \n"))
|
||||||
|
kit.servo[channel].angle = pos
|
||||||
14
testwalk4.py
Normal file
14
testwalk4.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import time
|
||||||
|
from adafruit_servokit import ServoKit
|
||||||
|
|
||||||
|
kit = ServoKit(channels=16)
|
||||||
|
|
||||||
|
leg = int(input("leg"))
|
||||||
|
|
||||||
|
kit.servo[leg].angle = 0
|
||||||
|
kit.servo[leg+6].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[leg].angle = 180
|
||||||
|
kit.servo[leg+6].angle = 180
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[leg].angle = 0
|
||||||
7
testwalk4.py.save
Normal file
7
testwalk4.py.save
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import time
|
||||||
|
from adafruit_servokit import ServoKit
|
||||||
|
|
||||||
|
kit = ServoKit(channels=16)
|
||||||
|
# smallest 0 biggest 110
|
||||||
|
while True:
|
||||||
|
kit.servo[].angle =
|
||||||
77
thr.py
Normal file
77
thr.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import threading
|
||||||
|
import time
|
||||||
|
from adafruit_servokit import ServoKit
|
||||||
|
|
||||||
|
kit = ServoKit(channels=16)
|
||||||
|
|
||||||
|
#leg = int(input("leg"))
|
||||||
|
def left2():
|
||||||
|
kit.servo[2].angle = 0
|
||||||
|
kit.servo[8].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[2].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[8].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[2].angle = 0
|
||||||
|
def left1():
|
||||||
|
kit.servo[1].angle = 0
|
||||||
|
kit.servo[7].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[1].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[7].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[1].angle = 0
|
||||||
|
def left0():
|
||||||
|
kit.servo[0].angle = 0
|
||||||
|
kit.servo[6].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[0].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[6].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[0].angle = 0
|
||||||
|
def right5():
|
||||||
|
kit.servo[5].angle = 0
|
||||||
|
kit.servo[11].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[5].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[11].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[5].angle = 0
|
||||||
|
def right4():
|
||||||
|
kit.servo[4].angle = 0
|
||||||
|
kit.servo[10].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[4].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[10].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[4].angle = 0
|
||||||
|
def right3():
|
||||||
|
kit.servo[3].angle = 0
|
||||||
|
kit.servo[9].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[3].angle = 110
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[9].angle = 0
|
||||||
|
time.sleep(1)
|
||||||
|
kit.servo[leg].angle = 0
|
||||||
|
|
||||||
|
|
||||||
|
leg0 = threading.Thread(target=left0, args=())
|
||||||
|
leg1 = threading.Thread(target=left1, args=())
|
||||||
|
leg2 = threading.Thread(target=left2, args=())
|
||||||
|
leg3 = threading.Thread(target=right3, args=())
|
||||||
|
leg4 = threading.Thread(target=right4, args=())
|
||||||
|
leg5 = threading.Thread(target=right5, args=())
|
||||||
|
leg0.start()
|
||||||
|
leg2.start()
|
||||||
|
leg4.start()
|
||||||
|
time.sleep(3)
|
||||||
|
leg1.start()
|
||||||
|
leg3.start()
|
||||||
|
leg5.start()
|
||||||
|
|
||||||
Reference in New Issue
Block a user