Skip to content

Commit 89e2a0a

Browse files
committed
Merge remote-tracking branch 'adafruit/master'
2 parents cfb187f + 9d15de0 commit 89e2a0a

71 files changed

Lines changed: 168979 additions & 231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import time
2+
import board
3+
import digitalio
4+
5+
relay = digitalio.DigitalInOut(board.A1)
6+
relay.direction = digitalio.Direction.OUTPUT
7+
8+
while True:
9+
relay.value = True
10+
time.sleep(1)
11+
relay.value = False
12+
time.sleep(1)

BLE_Client_Server/Eagle/CP_Solenoid3.brd

Lines changed: 1778 additions & 0 deletions
Large diffs are not rendered by default.

BLE_Client_Server/Eagle/CP_Solenoid3.sch

Lines changed: 6582 additions & 0 deletions
Large diffs are not rendered by default.

BLE_Client_Server/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Adafruit Learning System tutorial - A CircuitPython BLE Client & Server
2+
3+
Use Bluetooth to turn a server on and off and actively sense the server's status light
4+
5+
Follow the Adafruit learn guide here: https://learn.adafruit.com/circuitpython-ble-client-server/
6+
7+
Adafruit invests time and resources providing this open source code,
8+
please support Adafruit and open-source hardware by purchasing
9+
products from [Adafruit](https://www.adafruit.com)!
10+
11+
MIT license, project and code by rdagger
12+
13+
All text above, and the splash screen below must be included in any redistribution
14+
15+
-----------------------
16+
If you are looking to make changes/additions, please use the GitHub Issues and Pull Request mechanisms.
397 KB
Binary file not shown.
390 KB
Binary file not shown.
74.2 KB
Binary file not shown.
135 KB
Binary file not shown.
69.1 KB
Binary file not shown.

BLE_Client_Server/client.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from time import sleep
2+
from adafruit_ble.uart_client import UARTClient
3+
from adafruit_ble.scanner import Scanner
4+
from adafruit_bluefruit_connect.packet import Packet
5+
from adafruit_bluefruit_connect.button_packet import ButtonPacket
6+
from adafruit_bluefruit_connect.color_packet import ColorPacket
7+
from neopixel import NeoPixel
8+
from board import NEOPIXEL, SWITCH
9+
from adafruit_debouncer import Debouncer
10+
from digitalio import DigitalInOut, Direction, Pull
11+
import adafruit_fancyled.adafruit_fancyled as fancy
12+
13+
pin = DigitalInOut(SWITCH) # Set up built-in pushbutton switch
14+
pin.direction = Direction.INPUT
15+
pin.pull = Pull.UP
16+
switch = Debouncer(pin)
17+
18+
pixels = NeoPixel(NEOPIXEL, 1) # Set up built-in NeoPixel
19+
20+
AQUA = 0x00FFFF # (0, 255, 255)
21+
GREEN = 0x00FF00 # (0, 255, 0)
22+
ORANGE = 0xFF8000 # (255, 128, 0)
23+
RED = 0xFF0000 # (255, 0, 0)
24+
BLUE = 0x0000FF # (0, 0, 255)
25+
26+
gradients = {'Off': [(0.0, RED), (0.75, ORANGE)],
27+
'On': [(0.0, GREEN), (1.0, AQUA)]}
28+
palette = fancy.expand_gradient(gradients['Off'], 30)
29+
30+
gamma_levels = (0.25, 0.3, 0.15)
31+
color_index = 1
32+
fade_direction = 1
33+
34+
TARGET = 'a0:b4:c2:d0:e7:f2' # CHANGE TO YOUR BLE ADDRESS
35+
36+
button_packet = ButtonPacket("1", True) # Transmits pressed button 1
37+
38+
scanner = Scanner() # BLE Scanner
39+
uart_client = UARTClient() # BLE Client
40+
41+
while True:
42+
uart_addresses = []
43+
pixels[0] = BLUE # Blue LED indicates disconnected status
44+
pixels.show()
45+
46+
# Keep trying to find target UART peripheral
47+
while not uart_addresses:
48+
uart_addresses = uart_client.scan(scanner)
49+
for address in uart_addresses:
50+
if TARGET in str(address):
51+
uart_client.connect(address, 5) # Connect to target
52+
53+
while uart_client.connected: # Connected
54+
switch.update()
55+
if switch.fell: # Check for button press
56+
try:
57+
uart_client.write(button_packet.to_bytes()) # Transmit press
58+
except OSError:
59+
pass
60+
# Check for LED status receipt
61+
if uart_client.in_waiting:
62+
packet = Packet.from_stream(uart_client)
63+
if isinstance(packet, ColorPacket):
64+
if fancy.CRGB(*packet.color).pack() == GREEN: # Color match
65+
# Green indicates on state
66+
palette = fancy.expand_gradient(gradients['On'], 30)
67+
else:
68+
# Otherwise red indicates off
69+
palette = fancy.expand_gradient(gradients['Off'], 30)
70+
71+
# NeoPixel color fading routing
72+
color = fancy.palette_lookup(palette, color_index / 29)
73+
color = fancy.gamma_adjust(color, brightness=gamma_levels)
74+
c = color.pack()
75+
pixels[0] = c
76+
pixels.show()
77+
if color_index == 0 or color_index == 28:
78+
fade_direction *= -1 # Change direction
79+
color_index += fade_direction
80+
81+
sleep(0.02)

0 commit comments

Comments
 (0)