Skip to content

Commit c340043

Browse files
committed
porting bluefruit play to clue
1 parent 1aea90e commit c340043

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
All text above, and the splash screen below must be included in
1212
any redistribution
1313
*********************************************************************/
14+
15+
/* This sketch demonstrate the BLE Adafruit Service that is used with
16+
* "Adafruit Bluefruit Playground" app. Supported boards are
17+
* - Circuit Playground Bluefruit (https://www.adafruit.com/product/4333)
18+
* - CLUE nRF52840 (https://www.adafruit.com/product/4500)
19+
*/
20+
1421
#include <Adafruit_LittleFS.h>
1522
#include <InternalFileSystem.h>
1623
#include <bluefruit.h>
1724
#include <BLEAdafruitService.h>
18-
#include <Adafruit_CircuitPlayground.h>
1925

2026
// BLE Service
2127
BLEDfu bledfu; // OTA DFU service
@@ -32,40 +38,75 @@ BLEAdafruitTone bleTone;
3238

3339
BLEAdafruitAddressablePixel blePixel;
3440

35-
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, CPLAY_NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
41+
// Circuit Playground Bluefruit
42+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
43+
#include <Adafruit_CircuitPlayground.h>
44+
45+
#define DEVICE_NAME "CPlay"
46+
#define NEOPIXEL_COUNT 10
47+
48+
49+
#elif defined ARDUINO_NRF52840_CLUE
50+
51+
#define DEVICE_NAME "CLUE"
52+
#define NEOPIXEL_COUNT 1
53+
54+
55+
#else
56+
#error "Board is not supported"
57+
#endif
58+
59+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
3660

3761
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
3862
{
3963
uint32_t button = 0;
4064

65+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
4166
button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 );
4267
button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 );
4368
button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 );
4469

70+
#else
71+
// Button is active LOW on most board except CPlay
72+
73+
// No slide switch
74+
button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 );
75+
button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 );
76+
77+
#endif
78+
4579
memcpy(buf, &button, 4);
4680
return 4;
4781
}
4882

4983
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
5084
{
85+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
5186
float temp = CircuitPlayground.temperature();
5287
memcpy(buf, &temp, 4);
88+
#endif
5389
return 4;
5490
}
5591

5692
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
5793
{
94+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
5895
float lux = CircuitPlayground.lightSensor();
5996
memcpy(buf, &lux, 4);
97+
#endif
6098
return 4;
6199
}
62100

63101
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
64102
{
65103
float accel[3];
104+
105+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
66106
accel[0] = CircuitPlayground.motionX();
67107
accel[1] = CircuitPlayground.motionY();
68108
accel[2] = CircuitPlayground.motionZ();
109+
#endif
69110

70111
memcpy(buf, accel, sizeof(accel));
71112
return sizeof(accel);
@@ -79,7 +120,19 @@ void setup()
79120
Serial.println("Bluefruit52 BLEUART Example");
80121
Serial.println("---------------------------\n");
81122

123+
#if defined ARDUINO_NRF52840_CIRCUITPLAY
82124
CircuitPlayground.begin();
125+
#else
126+
127+
// Button
128+
pinMode(PIN_BUTTON1, INPUT_PULLUP);
129+
pinMode(PIN_BUTTON2, INPUT_PULLUP);
130+
131+
// Buzzer Speaker
132+
pinMode(PIN_BUZZER, OUTPUT);
133+
#endif
134+
135+
83136

84137
// Setup the BLE LED to be enabled on CONNECT
85138
// Note: This is actually the default behaviour, but provided
@@ -92,8 +145,8 @@ void setup()
92145
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
93146

94147
Bluefruit.begin();
95-
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
96-
Bluefruit.setName("Bluefruit52");
148+
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
149+
Bluefruit.setName(DEVICE_NAME);
97150
//Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
98151
Bluefruit.Periph.setConnectCallback(connect_callback);
99152
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
@@ -127,7 +180,7 @@ void setup()
127180
bleButton.setMeasureCallback(measure_button);
128181
bleButton.setPeriod(0); // only notify if there is changes with buttons
129182

130-
bleTone.begin(CPLAY_BUZZER);
183+
bleTone.begin(PIN_BUZZER);
131184

132185
strip.begin();
133186
blePixel.begin(&strip);
@@ -160,9 +213,8 @@ void startAdv(void)
160213

161214
Bluefruit.Advertising.addManufacturerData(&mfr_adv, sizeof(mfr_adv));
162215

163-
// Secondary Scan Response packet (optional)
164-
// Since there is no room for 'Name' in Advertising packet
165-
Bluefruit.ScanResponse.addName();
216+
// Add name to advertising, since there is enough room
217+
Bluefruit.Advertising.addName();
166218

167219
/* Start Advertising
168220
* - Enable auto advertising if disconnected

0 commit comments

Comments
 (0)