Ejemplo n.º 1
0
class BLEHandler(LoggingHandler):
    """Send logging output to the BLE uart port."""

    def __init__(self):
        """Create an instance.

        :param uart: the busio.UART instance to which to write messages

        """
        self._advertising_now = False
        self._uart = UARTServer()
        self._uart.start_advertising()

    def format(self, level, msg):
        """Generate a string to log.

        :param level: The level at which to log
        :param msg: The core message

        """
        return super().format(level, msg) + '\r\n'

    def emit(self, level, msg):
        """Generate the message and write it to the UART.

        :param level: The level at which to log
        :param msg: The core message

        """
        while not self._uart.connected:
            pass
        data = bytes(self.format(level, msg), 'utf-8')
        self._uart.write(data)
Ejemplo n.º 2
0
    def __init__(self):
        """Create an instance.

        :param uart: the busio.UART instance to which to write messages

        """
        self._advertising_now = False
        self._uart = UARTServer()
        self._uart.start_advertising()
Ejemplo n.º 3
0
from adafruit_ble.uart import UARTServer
import time
import board
from digitalio import DigitalInOut, Direction, Pull

uart = UARTServer()

FWD_PIN = DigitalInOut(board.P0_15)
REV_PIN = DigitalInOut(board.P0_17)
SLOW_PIN = DigitalInOut(board.P0_20)
FAST_PIN = DigitalInOut(board.P0_22)
FSTEP_PIN = DigitalInOut(board.P0_24)
RSTEP_PIN = DigitalInOut(board.P1_00)

Rled = DigitalInOut(board.LED2_R)
Gled = DigitalInOut(board.LED2_G)

FWD_PIN.direction = Direction.OUTPUT
REV_PIN.direction = Direction.OUTPUT
SLOW_PIN.direction = Direction.OUTPUT
FAST_PIN.direction = Direction.OUTPUT
FSTEP_PIN.direction = Direction.OUTPUT
RSTEP_PIN.direction = Direction.OUTPUT

Rled.direction = Direction.OUTPUT
Gled.direction = Direction.OUTPUT

fwd_cmd = str.encode("f")
rev_cmd = str.encode("r")
fast_cmd = str.encode("h")
slow_cmd = str.encode("l")
    fancy.CRGB(0, 68, 214)
]

# Declare a NeoPixel object on NEOPIXEL_PIN with NUM_LEDS pixels,
# no auto-write.
# Set brightness to max because we'll be using FancyLED's brightness control.
pixels = neopixel.NeoPixel(NEOPIXEL_PIN,
                           NUM_LEDS,
                           brightness=1.0,
                           auto_write=False)

offset = 0  # Positional offset into color palette to get it to 'spin'
offset_increment = 1
OFFSET_MAX = 1000000

uart_server = UARTServer()


def set_palette(palette):
    for i in range(NUM_LEDS):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, (offset + i) / NUM_LEDS)
        color = fancy.gamma_adjust(color, brightness=0.25)
        pixels[i] = color.pack()
    pixels.show()


# set initial palette to run on startup
palette_choice = PALETTE_RAINBOW