11
11
All text above, and the splash screen below must be included in
12
12
any redistribution
13
13
*********************************************************************/
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
+
14
21
#include < Adafruit_LittleFS.h>
15
22
#include < InternalFileSystem.h>
16
23
#include < bluefruit.h>
17
24
#include < BLEAdafruitService.h>
18
- #include < Adafruit_CircuitPlayground.h>
19
25
20
26
// BLE Service
21
27
BLEDfu bledfu; // OTA DFU service
@@ -32,40 +38,75 @@ BLEAdafruitTone bleTone;
32
38
33
39
BLEAdafruitAddressablePixel blePixel;
34
40
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);
36
60
37
61
uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
38
62
{
39
63
uint32_t button = 0 ;
40
64
65
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
41
66
button |= ( CircuitPlayground.slideSwitch () ? 0x01 : 0x00 );
42
67
button |= ( CircuitPlayground.leftButton () ? 0x02 : 0x00 );
43
68
button |= ( CircuitPlayground.rightButton () ? 0x04 : 0x00 );
44
69
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
+
45
79
memcpy (buf, &button, 4 );
46
80
return 4 ;
47
81
}
48
82
49
83
uint16_t measure_temperature (uint8_t * buf, uint16_t bufsize)
50
84
{
85
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
51
86
float temp = CircuitPlayground.temperature ();
52
87
memcpy (buf, &temp, 4 );
88
+ #endif
53
89
return 4 ;
54
90
}
55
91
56
92
uint16_t measure_light_sensor (uint8_t * buf, uint16_t bufsize)
57
93
{
94
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
58
95
float lux = CircuitPlayground.lightSensor ();
59
96
memcpy (buf, &lux, 4 );
97
+ #endif
60
98
return 4 ;
61
99
}
62
100
63
101
uint16_t measure_accel (uint8_t * buf, uint16_t bufsize)
64
102
{
65
103
float accel[3 ];
104
+
105
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
66
106
accel[0 ] = CircuitPlayground.motionX ();
67
107
accel[1 ] = CircuitPlayground.motionY ();
68
108
accel[2 ] = CircuitPlayground.motionZ ();
109
+ #endif
69
110
70
111
memcpy (buf, accel, sizeof (accel));
71
112
return sizeof (accel);
@@ -79,7 +120,19 @@ void setup()
79
120
Serial.println (" Bluefruit52 BLEUART Example" );
80
121
Serial.println (" ---------------------------\n " );
81
122
123
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
82
124
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
+
83
136
84
137
// Setup the BLE LED to be enabled on CONNECT
85
138
// Note: This is actually the default behaviour, but provided
@@ -92,8 +145,8 @@ void setup()
92
145
Bluefruit.configPrphBandwidth (BANDWIDTH_MAX);
93
146
94
147
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 );
97
150
// Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
98
151
Bluefruit.Periph .setConnectCallback (connect_callback);
99
152
Bluefruit.Periph .setDisconnectCallback (disconnect_callback);
@@ -127,7 +180,7 @@ void setup()
127
180
bleButton.setMeasureCallback (measure_button);
128
181
bleButton.setPeriod (0 ); // only notify if there is changes with buttons
129
182
130
- bleTone.begin (CPLAY_BUZZER );
183
+ bleTone.begin (PIN_BUZZER );
131
184
132
185
strip.begin ();
133
186
blePixel.begin (&strip);
@@ -160,9 +213,8 @@ void startAdv(void)
160
213
161
214
Bluefruit.Advertising .addManufacturerData (&mfr_adv, sizeof (mfr_adv));
162
215
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 ();
166
218
167
219
/* Start Advertising
168
220
* - Enable auto advertising if disconnected
0 commit comments