Пример #1
0
class DummyAudio:
    def play(self, f, loop=False):
        pass

    def stop(self):
        pass

    def mute(self, mute):
        pass


i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
spi = board.SPI()
displayio.release_displays()
while not spi.try_lock():
    pass
spi.configure(baudrate=24000000)
spi.unlock()
ss.pin_mode(8, ss.OUTPUT)
ss.digital_write(8, True) # reset display
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80,
                            rowstart=24)
del _INIT_SEQUENCE
buttons = GamePadSeesaw(ss)
audio = DummyAudio()
backlight = PWMOut(ss, 5)
backlight.duty_cycle = 0
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor
import board
import time

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
motor_a.throttle = 0.5  # half speed forward

# Create drive (PWM) object
my_drive = PWMOut(seesaw, 13)  # Drive 1 is on s.s. pin 13
my_drive.frequency = 1000  # Our default frequency is 1KHz

while True:

    my_drive.duty_cycle = 32768  # half on
    time.sleep(0.8)

    my_drive.duty_cycle = 16384  # dim
    time.sleep(0.1)

    # and repeat!
Пример #3
0
MOUTH_END = 105

# Create servos list
servos = []
for ss_pin in (17, 16):  #17 is labeled 1 on CRICKIT, 16 is labeled 2
    pwm = PWMOut(seesaw, ss_pin)
    pwm.frequency = 50  #must be 50 cannot change
    _servo = servo.Servo(pwm, min_pulse=400, max_pulse=2500)
    servos.append(_servo)
# Starting servo locations
servos[0].angle = BELL_START
servos[1].angle = MOUTH_START

# For the fog machine we actually use the PWM on the motor port cause it really needs 5V!
fog_off = PWMOut(seesaw, 22)
fog_off.duty_cycle = 0
fog_on = PWMOut(seesaw, 23)
fog_on.duty_cycle = 0

# Audio playback object and helper to play a full file
a = audioio.AudioOut(board.A0)


def play_file(wavfile):
    with open(wavfile, "rb") as file:
        wavf = audioio.WaveFile(file)
        a.play(wavf)
        while a.playing:
            servos[1].angle = MOUTH_START
            time.sleep(.2)
            servos[1].angle = MOUTH_END