Skip to content

Commit ed7460d

Browse files
authored
Merge branch 'master' into jeplayer-macos-metadata
2 parents 63582e7 + 17653a8 commit ed7460d

File tree

26 files changed

+1254
-4
lines changed

26 files changed

+1254
-4
lines changed

BLE_Candy_Claw/code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import time
2+
import board
3+
import pulseio
4+
from adafruit_motor import servo
5+
from adafruit_bluefruit_connect.packet import Packet
6+
from adafruit_bluefruit_connect.button_packet import ButtonPacket
7+
from adafruit_ble import BLERadio
8+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
9+
from adafruit_ble.services.nordic import UARTService
10+
11+
ble = BLERadio()
12+
uart = UARTService()
13+
advertisement = ProvideServicesAdvertisement(uart)
14+
15+
pwm = pulseio.PWMOut(board.A3, duty_cycle=2 ** 15, frequency=50)
16+
17+
my_servo = servo.Servo(pwm)
18+
19+
while True:
20+
print("WAITING...")
21+
# Advertise when not connected.
22+
ble.start_advertising(advertisement)
23+
while not ble.connected:
24+
pass
25+
26+
# Connected
27+
ble.stop_advertising()
28+
print("CONNECTED")
29+
30+
# Loop and read packets
31+
while ble.connected:
32+
if uart.in_waiting:
33+
packet = Packet.from_stream(uart)
34+
if isinstance(packet, ButtonPacket):
35+
# if buttons in the app are pressed
36+
if packet.pressed:
37+
if packet.button == ButtonPacket.DOWN:
38+
print("pressed down")
39+
for angle in range(90, 170, 90): # 90 - 170 degrees, 90 degrees at a time.
40+
my_servo.angle = angle
41+
time.sleep(0.05)
42+
if packet.button == ButtonPacket.UP:
43+
print("pressed up")
44+
for angle in range(170, 90, -90): # 170 - 90 degrees, 9 degrees at a time.
45+
my_servo.angle = angle
46+
time.sleep(0.05)
47+
# Disconnected
48+
print("DISCONNECTED")

BLE_Host_Computer/ble_eval_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Connect to an "eval()" service over BLE UART.
2+
3+
from adafruit_ble import BLERadio
4+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
5+
from adafruit_ble.services.nordic import UARTService
6+
7+
ble = BLERadio()
8+
9+
uart_connection = None
10+
11+
while True:
12+
if not uart_connection:
13+
print("Trying to connect...")
14+
for adv in ble.start_scan(ProvideServicesAdvertisement):
15+
if UARTService in adv.services:
16+
uart_connection = ble.connect(adv)
17+
print("Connected")
18+
break
19+
ble.stop_scan()
20+
21+
if uart_connection and uart_connection.connected:
22+
uart_service = uart_connection[UARTService]
23+
while uart_connection.connected:
24+
s = input("Eval: ")
25+
uart_service.write(s.encode("utf-8"))
26+
uart_service.write(b'\n')
27+
print(uart_service.readline().decode("utf-8"))

BLE_Host_Computer/ble_eval_server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Provide an "eval()" service over BLE UART.
2+
3+
from adafruit_ble import BLERadio
4+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
5+
from adafruit_ble.services.nordic import UARTService
6+
7+
ble = BLERadio()
8+
uart = UARTService()
9+
advertisement = ProvideServicesAdvertisement(uart)
10+
11+
while True:
12+
ble.start_advertising(advertisement)
13+
print("Waiting to connect")
14+
while not ble.connected:
15+
pass
16+
print("Connected")
17+
while ble.connected:
18+
s = uart.readline()
19+
if s:
20+
try:
21+
result = str(eval(s))
22+
except Exception as e:
23+
result = repr(e)
24+
uart.write(result.encode("utf-8"))

Bitcoin_Matrix/bitcoin_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def text_transform(val):
3131
json_path=DATA_LOCATION,
3232
status_neopixel=board.NEOPIXEL,
3333
default_bg=cwd + "/bitcoin_background.bmp",
34-
debug=True,
34+
debug=False,
3535
)
3636

3737
matrixportal.add_text(

Circuit_Playground_Classic_Fruit_Drums/.cpc.test.only

Whitespace-only changes.

Circuit_Playground_Classic_Fruit_Drums/CapTouchBasic/.cpc.test.only

Whitespace-only changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
// Circuit Playground Capacitive Touch Basic
3+
//
4+
// Print text messages for each touch pad.
5+
//
6+
// Author: Carter Nelson
7+
// MIT License (https://opensource.org/licenses/MIT)
8+
9+
#include <Adafruit_CircuitPlayground.h>
10+
11+
#define CAP_THRESHOLD 50
12+
#define DEBOUNCE 250
13+
14+
uint8_t pads[] = {3, 2, 0, 1, 12, 6, 9, 10};
15+
uint8_t numberOfPads = sizeof(pads)/sizeof(uint8_t);
16+
17+
////////////////////////////////////////////////////////////////////////////
18+
void takeAction(uint8_t pad) {
19+
Serial.print("PAD "); Serial.print(pad); Serial.print(" says: ");
20+
switch (pad) {
21+
case 3:
22+
Serial.println("The goggles! They do nothing!");
23+
break;
24+
case 2:
25+
Serial.println("Dental plan!");
26+
break;
27+
case 0:
28+
Serial.println("Lisa needs braces.");
29+
break;
30+
case 1:
31+
Serial.println("I call the large one Bitey.");
32+
break;
33+
case 12:
34+
Serial.println("I'm Idaho!");
35+
break;
36+
case 6:
37+
Serial.println("Monorail!");
38+
break;
39+
case 9:
40+
Serial.println("I choo-choo choose you.");
41+
break;
42+
case 10:
43+
Serial.println("Maaaattlllock!");
44+
break;
45+
default:
46+
Serial.println("THIS SHOULD NEVER HAPPEN.");
47+
}
48+
}
49+
50+
////////////////////////////////////////////////////////////////////////////
51+
boolean capButton(uint8_t pad) {
52+
// Check if capacitive touch exceeds threshold.
53+
if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
54+
return true;
55+
} else {
56+
return false;
57+
}
58+
}
59+
60+
////////////////////////////////////////////////////////////////////////////
61+
void setup() {
62+
// Initialize serial.
63+
Serial.begin(9600);
64+
65+
// Initialize Circuit Playground library.
66+
CircuitPlayground.begin();
67+
}
68+
69+
////////////////////////////////////////////////////////////////////////////
70+
void loop() {
71+
// Loop over every pad.
72+
for (int i=0; i<numberOfPads; i++) {
73+
74+
// Check if pad is touched.
75+
if (capButton(pads[i])) {
76+
77+
// Do something.
78+
takeAction(pads[i]);
79+
80+
// But not too often.
81+
delay(DEBOUNCE);
82+
}
83+
}
84+
}

Circuit_Playground_Classic_Fruit_Drums/CapTouchKeyboard/.cpc.test.only

Whitespace-only changes.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
// Circuit Playground Capacitive Touch Tones
3+
//
4+
// Send keyboard and mouse events for each touch pad.
5+
// https://www.arduino.cc/en/Reference/MouseKeyboard
6+
//
7+
// Author: Carter Nelson
8+
// MIT License (https://opensource.org/licenses/MIT)
9+
10+
#include <Adafruit_CircuitPlayground.h>
11+
#include <Mouse.h>
12+
#include <Keyboard.h>
13+
14+
#define CAP_THRESHOLD 50
15+
#define DEBOUNCE 250
16+
17+
uint8_t pads[] = {3, 2, 0, 1, 12, 6, 9, 10};
18+
uint8_t numberOfPads = sizeof(pads)/sizeof(uint8_t);
19+
20+
boolean emulatorActive = false;
21+
22+
////////////////////////////////////////////////////////////////////////////
23+
void takeAction(uint8_t pad) {
24+
Serial.print("PAD "); Serial.println(pad);
25+
switch (pad) {
26+
case 3:
27+
sendKey(KEY_LEFT_ARROW);
28+
break;
29+
case 2:
30+
sendKey(KEY_UP_ARROW);
31+
break;
32+
case 0:
33+
sendKey(KEY_DOWN_ARROW);
34+
break;
35+
case 1:
36+
sendKey(KEY_RIGHT_ARROW);
37+
break;
38+
case 12:
39+
sendKey(' ');
40+
break;
41+
case 6:
42+
sendMouse(MOUSE_LEFT);
43+
break;
44+
case 9:
45+
sendMouse(MOUSE_MIDDLE);
46+
break;
47+
case 10:
48+
sendMouse(MOUSE_RIGHT);
49+
break;
50+
default:
51+
Serial.println("THIS SHOULD NEVER HAPPEN.");
52+
}
53+
}
54+
55+
////////////////////////////////////////////////////////////////////////////
56+
boolean capButton(uint8_t pad) {
57+
// Check if capacitive touch exceeds threshold.
58+
if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
59+
return true;
60+
} else {
61+
return false;
62+
}
63+
}
64+
65+
////////////////////////////////////////////////////////////////////////////
66+
void sendKey(char key) {
67+
Keyboard.press(key);
68+
Keyboard.releaseAll();
69+
}
70+
71+
////////////////////////////////////////////////////////////////////////////
72+
void sendMouse(char key) {
73+
Mouse.click(key);
74+
}
75+
76+
////////////////////////////////////////////////////////////////////////////
77+
void setup() {
78+
// Initialize serial.
79+
Serial.begin(9600);
80+
81+
// Initialize Circuit Playground library.
82+
CircuitPlayground.begin();
83+
}
84+
85+
////////////////////////////////////////////////////////////////////////////
86+
void loop() {
87+
// Indicate emulator status on red LED.
88+
CircuitPlayground.redLED(emulatorActive);
89+
90+
// Check slide switch.
91+
if (!CircuitPlayground.slideSwitch()) {
92+
93+
//-----------| EMULATOR OFF |-------------
94+
if (emulatorActive) {
95+
Keyboard.end();
96+
Mouse.end();
97+
emulatorActive = false;
98+
}
99+
100+
} else {
101+
102+
//-----------| EMULATOR ON |-------------
103+
if (!emulatorActive) {
104+
Keyboard.begin();
105+
Mouse.begin();
106+
emulatorActive = true;
107+
}
108+
109+
// Loop over every pad.
110+
for (int i=0; i<numberOfPads; i++) {
111+
112+
// Check if pad is touched.
113+
if (capButton(pads[i])) {
114+
115+
// Do something.
116+
takeAction(pads[i]);
117+
118+
// But not too often.
119+
delay(DEBOUNCE);
120+
}
121+
}
122+
}
123+
}

Circuit_Playground_Classic_Fruit_Drums/CapTouchMIDIDrums/.cpc.test.only

Whitespace-only changes.

0 commit comments

Comments
 (0)