def main(addon):
    badge.show_bitmap('drivers/assets/speaker.bmp')

    audio = PWMOut(board.GPIO1,
                   duty_cycle=0,
                   frequency=440,
                   variable_frequency=True)
    led = digitalio.DigitalInOut(board.GPIO2)
    led.switch_to_output(True)
    try:
        for (notename, eigths) in sequence:
            length = eigths * 0.1
            if notename:
                led.value = False
                audio.frequency = round(note(notename))
                audio.duty_cycle = 0x8000
            time.sleep(length)
            led.value = True
            audio.duty_cycle = 0
            time.sleep(0.025)

        time.sleep(3)
    finally:
        led.deinit()
        audio.deinit()
Example #2
0
import board
from pulseio import PWMOut
from digitalio import DigitalInOut, Direction, Pull
from adafruit_ble.uart import UARTServer
from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.color_packet import ColorPacket

r = PWMOut(board.RGB_LED_RED, duty_cycle=0)
g = PWMOut(board.RGB_LED_GREEN, duty_cycle=0)
b = PWMOut(board.RGB_LED_BLUE, duty_cycle=0)

uart_server = UARTServer()

while True:
    uart_server.start_advertising()
    while not uart_server.connected:
        pass

    while uart_server.connected:
        packet = Packet.from_stream(uart_server)
        if isinstance(packet, ColorPacket):
            print(packet.color)
            dc = [-257 * c + 65535 for c in packet.color]
            r.duty_cycle, g.duty_cycle, b.duty_cycle = dc
Example #3
0
"""
FILE: main.py
DESC: Motor controller obeys commands from sensors
"""

import board
import busio
from motor import DCMotor
from time import sleep
from pulseio import PWMOut

uart = busio.UART(None, board.RX, baudrate=9600)
left = PWMOut(board.D2)
right = PWMOut(board.D0)

left.duty_cycle = 30000  # int(0xffff * abs(0.5))


def stop():
    print("Stopping!")

    try:
        left.duty_cycle = 0
        right.duty_cycle = 0
    except Exception as e:
        print("Exception in stop(): " + e.args[0])
        pass


while True:
    data = uart.read(1)
Example #4
0
import time
import board
from pulseio import PWMOut

FADE_SPEED     = 0.1  # Smaller number = faster
FADE_INCREMENT = 4000 # How much to adjust the brightness per cycle

PWM_FULL = 65535

# Setup LED
led = PWMOut(board.LED1, frequency=5000, duty_cycle=0)

# Fade infinitely
direction = 1
brightness = 0
while True:
  brightness += FADE_INCREMENT * direction

  # Switch directions when we get to the limits
  if direction < 0 and brightness <= 0:
    brightness = 0
    direction = 1
  elif direction > 0 and brightness >= PWM_FULL:
    brightness = PWM_FULL
    direction = -1

  # Set PWM value
  led.duty_cycle = brightness

  time.sleep(FADE_SPEED)