12
12
any redistribution
13
13
*********************************************************************/
14
14
15
+ #if defined(ARDUINO_NRF52840_CIRCUITPLAY) || defined(ARDUINO_NRF52840_CLUE)
16
+ #define USE_ARCADA
17
+ #endif
18
+
19
+ #ifdef USE_ARCADA
20
+ #include < Adafruit_Arcada.h>
21
+
22
+ Adafruit_Arcada arcada;
23
+ Adafruit_SPITFT* tft;
24
+ #endif
25
+
15
26
#include < SPI.h>
16
27
#include < Adafruit_GFX.h>
17
28
#include < bluefruit.h>
33
44
34
45
/* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App.
35
46
* Following TFT Display are supported
36
- * - TFT 3.5" : FeatherWing https://www.adafruit.com/product/3651
37
- * - TFT 2.4" : FeatherWing https://www.adafruit.com/product/3315
47
+ * - Circuit Playground Bluefruit: https://www.adafruit.com/product/4333
38
48
* - TFT Gizmo : https://www.adafruit.com/product/4367
39
49
* - Adafruit CLUE : https://www.adafruit.com/product/4500
40
50
*/
41
51
42
- #define TFT_NO_DISPLAY 0
43
- #define TFT_GIZMO 1 // used with Circuit Playground Bluefruit
44
- #define TFT_CLUE 2 // CLUE's on-board display
45
- #define TFT_24_FEATHERWING 3
46
- #define TFT_35_FEATHERWING 4
47
-
48
-
49
- #if defined(ARDUINO_NRF52840_CIRCUITPLAY)
50
- // Circuit Playground Bluefruit use with TFT GIZMO
51
- #define TFT_IN_USE TFT_GIZMO
52
- #define DEVICE_NAME " CPLAY"
53
-
54
- #include " Adafruit_ST7789.h"
55
- Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, 0 , 1 , -1 ); // CS = 0, DC = 1
56
-
57
- #elif defined(ARDUINO_NRF52840_CLUE)
58
- // CLUE use on-board TFT
59
- #define TFT_IN_USE TFT_CLUE
60
- #define DEVICE_NAME " CLUE"
61
-
62
- #include " Adafruit_ST7789.h"
63
- Adafruit_ST7789 tft = Adafruit_ST7789(&SPI1, PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RST);
64
-
65
- #else
66
- // [Configurable] For other boards please select which external display to match your hardware setup
67
- #define TFT_IN_USE TFT_24_FEATHERWING
68
- #define DEVICE_NAME " Feather"
69
-
70
- #if defined(ARDUINO_NRF52832_FEATHER)
71
- // Feather nRF52832 pin map is different from others
72
- #define TFT_DC 11
73
- #define TFT_CS 31
74
- #else
75
- // Default for others
76
- #define TFT_DC 10
77
- #define TFT_CS 9
78
- #endif
79
-
80
- #if TFT_IN_USE == TFT_35_FEATHERWING
81
- #include " Adafruit_HX8357.h"
82
- Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
83
-
84
- #elif TFT_IN_USE == TFT_24_FEATHERWING
85
- #include < Adafruit_ILI9341.h>
86
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
87
- #endif // TFT
88
-
89
- #endif // board variants
90
-
91
-
92
- #define COLOR_WHITE 0xFFFF
93
- #define COLOR_BLACK 0x0000
94
- #define COLOR_YELLOW 0xFFE0
95
- #define COLOR_GREEN 0x07E0
96
- #define COLOR_RED 0xF800
97
-
98
52
// BLE Service
99
53
BLEUart bleuart; // uart over ble
100
54
@@ -105,35 +59,14 @@ void setup()
105
59
Serial.println (" Bluefruit52 Pairing Display Example" );
106
60
Serial.println (" -----------------------------------\n " );
107
61
108
- #if TFT_IN_USE == TFT_CLUE
109
- tft.init (240 , 240 );
110
- tft.setRotation (1 );
111
-
112
- // Screen refresh rate control (datasheet 9.2.18, FRCTRL2)
113
- uint8_t rtna = 0x01 ;
114
- tft.sendCommand (0xC6 , &rtna, 1 );;
115
-
116
- // turn back light on
117
- uint8_t backlight = PIN_TFT_LITE;
118
- pinMode (backlight, OUTPUT);
119
- digitalWrite (backlight, HIGH);
120
-
121
- #elif TFT_IN_USE == TFT_GIZMO
122
- tft.init (240 , 240 );
123
- tft.setRotation (2 );
124
-
125
- // turn back light on
126
- uint8_t backlight = A3;
127
- pinMode (backlight, OUTPUT);
128
- digitalWrite (backlight, HIGH);
129
-
130
- #elif TFT_IN_USE != TFT_NO_DISPLAY
131
- tft.begin ();
132
-
133
- #endif // TFT
62
+ arcada.arcadaBegin ();
63
+ arcada.displayBegin ();
64
+ arcada.setBacklight (255 );
134
65
135
- pinMode (PIN_BUTTON1, INPUT_PULLUP);
136
- pinMode (PIN_BUTTON2, INPUT_PULLUP);
66
+ tft = arcada.display ;
67
+ tft->setCursor (0 , 0 );
68
+ tft->setTextWrap (true );
69
+ tft->setTextSize (2 );
137
70
138
71
// Setup the BLE LED to be enabled on CONNECT
139
72
// Note: This is actually the default behavior, but provided
@@ -147,7 +80,6 @@ void setup()
147
80
148
81
Bluefruit.begin ();
149
82
Bluefruit.setTxPower (4 ); // Check bluefruit.h for supported values
150
- Bluefruit.setName (DEVICE_NAME);
151
83
152
84
// clear bonds if BUTTON A is pressed
153
85
Serial.println (" Hold button A to clear bonds ..... " );
@@ -182,12 +114,12 @@ void setup()
182
114
bleuart.setPermission (SECMODE_ENC_WITH_MITM);
183
115
bleuart.begin ();
184
116
185
- #if TFT_IN_USE != TFT_NO_DISPLAY
186
- tft. fillScreen (COLOR_BLACK );
187
- tft. setTextColor (COLOR_WHITE );
188
- tft. setTextSize (2 );
189
- tft. setCursor (0 , 0 );
190
- tft. print (" Advertising..." );
117
+ #ifdef USE_ARCADA
118
+ tft-> fillScreen (ARCADA_BLACK );
119
+ tft-> setTextColor (ARCADA_WHITE );
120
+ tft-> setTextSize (2 );
121
+ tft-> setCursor (0 , 0 );
122
+ tft-> print (" Advertising..." );
191
123
#endif
192
124
193
125
Serial.println (" Please use Adafruit's Bluefruit LE app to connect in UART mode" );
@@ -261,11 +193,11 @@ void connect_callback(uint16_t conn_handle)
261
193
Serial.print (" Connected to " );
262
194
Serial.println (central_name);
263
195
264
- #if TFT_IN_USE != TFT_NO_DISPLAY
265
- tft. fillScreen (COLOR_BLACK );
266
- tft. setTextSize (2 );
267
- tft. setCursor (0 , 0 );
268
- tft. println (" Connected" );
196
+ #ifdef USE_ARCADA
197
+ tft-> fillScreen (ARCADA_BLACK );
198
+ tft-> setTextSize (2 );
199
+ tft-> setCursor (0 , 0 );
200
+ tft-> println (" Connected" );
269
201
#endif
270
202
}
271
203
@@ -279,15 +211,15 @@ bool pairing_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bo
279
211
Serial.println (" Pairing Passkey" );
280
212
Serial.printf (" %.3s %.3s\n " , passkey, passkey+3 );
281
213
282
- #if TFT_IN_USE != TFT_NO_DISPLAY
283
- tft. fillScreen (COLOR_BLACK );
284
- tft. println (" Pairing Passkey\n " );
285
- tft. setTextColor (COLOR_YELLOW );
286
- tft. setTextSize (4 );
287
- tft. printf (" %.3s %.3s\n " , passkey, passkey+3 );
214
+ #ifdef USE_ARCADA
215
+ tft-> fillScreen (ARCADA_BLACK );
216
+ tft-> println (" Pairing Passkey\n " );
217
+ tft-> setTextColor (ARCADA_YELLOW );
218
+ tft-> setTextSize (4 );
219
+ tft-> printf (" %.3s %.3s\n " , passkey, passkey+3 );
288
220
289
- tft. setTextColor (COLOR_WHITE );
290
- tft. setTextSize (2 );
221
+ tft-> setTextColor (ARCADA_WHITE );
222
+ tft-> setTextSize (2 );
291
223
#endif
292
224
293
225
@@ -296,18 +228,18 @@ bool pairing_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bo
296
228
Serial.println (" Do you want to pair" );
297
229
Serial.println (" Press Button A to accept, Button B to reject" );
298
230
299
- #if TFT_IN_USE != TFT_NO_DISPLAY
300
- tft. println (" \n Do you accept ?\n\n " );
231
+ #ifdef USE_ARCADA
232
+ tft-> println (" \n Do you accept ?\n\n " );
301
233
302
- tft. setTextSize (3 );
303
- tft. setTextColor (COLOR_GREEN );
304
- tft. print (" << Yes" );
305
- tft. setTextColor (COLOR_RED );
306
- tft. println (" No >>" );
234
+ tft-> setTextSize (3 );
235
+ tft-> setTextColor (ARCADA_GREEN );
236
+ tft-> print (" << Yes" );
237
+ tft-> setTextColor (ARCADA_RED );
238
+ tft-> println (" No >>" );
307
239
308
- tft. setTextColor (COLOR_WHITE );
309
- tft. setTextSize (2 );
310
- tft. println ();
240
+ tft-> setTextColor (ARCADA_WHITE );
241
+ tft-> setTextSize (2 );
242
+ tft-> println ();
311
243
#endif
312
244
313
245
// wait until either button is pressed
@@ -343,30 +275,30 @@ void pairing_complete_callback(uint16_t conn_handle, uint8_t auth_status)
343
275
Serial.println (" Failed" );
344
276
}
345
277
346
- #if TFT_IN_USE != TFT_NO_DISPLAY
278
+ #ifdef USE_ARCADA
347
279
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
348
280
{
349
- tft. setTextColor (COLOR_GREEN );
350
- tft. println (" Succeeded" );
281
+ tft-> setTextColor (ARCADA_GREEN );
282
+ tft-> println (" Succeeded" );
351
283
}else
352
284
{
353
- tft. setTextColor (COLOR_RED );
354
- tft. println (" Failed" );
285
+ tft-> setTextColor (ARCADA_RED );
286
+ tft-> println (" Failed" );
355
287
}
356
288
357
- tft. setTextColor (COLOR_WHITE );
358
- tft. setTextSize (2 );
289
+ tft-> setTextColor (ARCADA_WHITE );
290
+ tft-> setTextSize (2 );
359
291
#endif
360
292
}
361
293
362
294
void connection_secured_callback (uint16_t conn_handle)
363
295
{
364
296
Serial.println (" Secured" );
365
297
366
- #if TFT_IN_USE != TFT_NO_DISPLAY
367
- tft. setTextColor (COLOR_YELLOW );
368
- tft. println (" secured" );
369
- tft. setTextColor (COLOR_WHITE );
298
+ #ifdef USE_ARCADA
299
+ tft-> setTextColor (ARCADA_YELLOW );
300
+ tft-> println (" secured" );
301
+ tft-> setTextColor (ARCADA_WHITE );
370
302
#endif
371
303
}
372
304
@@ -383,7 +315,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
383
315
Serial.println ();
384
316
Serial.print (" Disconnected, reason = 0x" ); Serial.println (reason, HEX);
385
317
386
- #if TFT_IN_USE != TFT_NO_DISPLAY
387
- tft. println (" Advertising ..." );
318
+ #ifdef USE_ARCADA
319
+ tft-> println (" Advertising ..." );
388
320
#endif
389
321
}
0 commit comments