Simple test¶
Ensure your device works with this simple test.
examples/caveble_simpletest.py¶
1# SPDX-FileCopyrightText: 2022 Phil Underwood
2#
3# SPDX-License-Identifier: Unlicense
4"""
5example that reads from the cdc data serial port in groups of four and prints
6to the console. The USB CDC data serial port will need enabling. This can be done
7by copying examples/usb_cdc_boot.py to boot.py in the CIRCUITPY directory
8
9Meanwhile a simple counter counts up every second and also prints
10to the console.
11"""
12import time
13
14import board
15import keypad
16from adafruit_ble import BLERadio
17from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
18import caveble
19
20ble = BLERadio()
21ble.name = "SAP6_AB"
22print(ble.name)
23survey_protocol = caveble.SurveyProtocolService()
24advertisement = ProvideServicesAdvertisement(survey_protocol)
25ble.start_advertising(advertisement)
26
27
28KEY_PINS = (board.D5, board.D9)
29keys = keypad.Keys(KEY_PINS, value_when_pressed=False, pull=True)
30
31compass = 0
32clino = 0
33distance = 5
34while True:
35 event = keys.events.get()
36 if event:
37 key_number = event.key_number
38 if event.pressed:
39 if key_number == 0:
40 # change the values to send
41 compass = (compass + 10.5) % 360
42 clino += 5.5
43 if clino > 90:
44 clino -= 180
45 distance = (distance + 3.4) % 10000
46 print(compass, clino, distance)
47 if key_number == 1:
48 survey_protocol.send_data(compass, clino, distance)
49 print("Data sent")
50 message = survey_protocol.poll()
51 if message:
52 print(f"Message received: {message}")
53 time.sleep(0.03)