Exemplo n.º 1
0
# CircuitPython NeoPixel Color Picker Example

import board
import neopixel
from adafruit_ble.uart_server import UARTServer
from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.color_packet import ColorPacket

uart_server = UARTServer()

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1)

while True:
    # Advertise when not connected.
    uart_server.start_advertising()
    while not uart_server.connected:
        pass

    while uart_server.connected:
        try:
            packet = Packet.from_stream(uart_server)
        except ValueError:
            print(
                "Caught a bad packet with a ValueError, discarding and trying again"
            )
            continue
        if isinstance(packet, ColorPacket):
            print(packet.color)
            pixels.fill(packet.color)
# CircuitPython Bluefruit LE Connect Plotter Example

import board
import analogio
import adafruit_thermistor
from adafruit_ble.uart_server import UARTServer

uart_server = UARTServer()

thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000,
                                            25, 3950)
light = analogio.AnalogIn(board.LIGHT)


def scale(value):
    """Scale the light sensor values from 0-65535 (AnalogIn range)
    to 0-50 (arbitrarily chosen to plot well with temperature)"""
    return value / 65535 * 50


while True:
    # Advertise when not connected.
    uart_server.start_advertising()
    while not uart_server.connected:
        pass

    while uart_server.connected:
        print(scale(light.value), thermistor.temperature)
        uart_server.write('{},{}\n'.format(scale(light.value),
                                           thermistor.temperature))
Exemplo n.º 3
0
from time import sleep
from adafruit_ble.uart_server import UARTServer
from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.button_packet import ButtonPacket
from adafruit_bluefruit_connect.color_packet import ColorPacket
from board import A0, D13
from analogio import AnalogIn
from digitalio import DigitalInOut, Direction

led = AnalogIn(A0)  # Initialize blue LED light detector

solenoid = DigitalInOut(D13)  # Initialize solenoid
solenoid.direction = Direction.OUTPUT
solenoid.value = False

uart_server = UARTServer()

while True:
    uart_server.start_advertising()  # Advertise when not connected.

    while not uart_server.connected:  # Wait for connection
        pass

    while uart_server.connected:  # Connected
        if uart_server.in_waiting:  # Check BLE commands
            packet = Packet.from_stream(uart_server)
            if isinstance(packet, ButtonPacket):
                if packet.button == '1' and packet.pressed:
                    solenoid.value = True  # Activate solenoid for 1 second
                    sleep(1)
                    solenoid.value = False
from adafruit_ble.uart_server import UARTServer

uart = UARTServer()

while True:
    uart.start_advertising()

    # Wait for a connection
    while not uart.connected:
        pass

    while uart.connected:
        # Returns b'' if nothing was read.
        one_byte = uart.read(1)
        if one_byte:
            uart.write(one_byte)

    # When disconnected, arrive here. Go back to the top
    # and start advertising again.