@@ -33,20 +33,23 @@ BLEBas blebas; // battery
33
33
BLEAdafruitTemperature bleTemp;
34
34
BLEAdafruitAccel bleAccel;
35
35
BLEAdafruitLightSensor bleLight;
36
+ BLEAdafruitGyro bleGyro;
37
+ BLEAdafruitMagnetic bleMagnetic;
38
+
36
39
BLEAdafruitButton bleButton;
37
40
BLEAdafruitTone bleTone;
38
41
39
42
BLEAdafruitAddressablePixel blePixel;
40
43
41
44
// Circuit Playground Bluefruit
42
- #if defined ARDUINO_NRF52840_CIRCUITPLAY
45
+ #if defined( ARDUINO_NRF52840_CIRCUITPLAY )
43
46
#include < Adafruit_CircuitPlayground.h>
44
47
45
48
#define DEVICE_NAME " CPlay"
46
49
#define NEOPIXEL_COUNT 10
47
50
48
51
49
- #elif defined ARDUINO_NRF52840_CLUE
52
+ #elif defined( ARDUINO_NRF52840_CLUE ) || defined( ARDUINO_NRF52840_FEATHER_SENSE )
50
53
#include < Adafruit_APDS9960.h>
51
54
#include < Adafruit_LSM6DS33.h>
52
55
#include < Adafruit_BMP280.h>
@@ -64,46 +67,49 @@ BLEAdafruitAddressablePixel blePixel;
64
67
65
68
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
66
69
67
- uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
70
+ uint16_t measure_temperature (uint8_t * buf, uint16_t bufsize)
68
71
{
69
- uint32_t button = 0 ;
72
+ float temp ;
70
73
71
74
#if defined ARDUINO_NRF52840_CIRCUITPLAY
72
- button |= ( CircuitPlayground.slideSwitch () ? 0x01 : 0x00 );
73
- button |= ( CircuitPlayground.leftButton () ? 0x02 : 0x00 );
74
- button |= ( CircuitPlayground.rightButton () ? 0x04 : 0x00 );
75
+ temp = CircuitPlayground.temperature ();
75
76
76
77
#elif defined ARDUINO_NRF52840_CLUE
77
- // Button is active LOW on most board except CPlay
78
-
79
- // No slide switch
80
- button |= ( digitalRead (PIN_BUTTON1) ? 0x00 : 0x02 );
81
- button |= ( digitalRead (PIN_BUTTON2) ? 0x00 : 0x04 );
78
+ temp = bmp280.readTemperature ();
82
79
83
80
#endif
84
81
85
- memcpy (buf, &button , 4 );
82
+ memcpy (buf, &temp , 4 );
86
83
return 4 ;
87
84
}
88
85
89
- uint16_t measure_temperature (uint8_t * buf, uint16_t bufsize)
90
- {
91
- float temp ;
86
+ uint16_t measure_accel (uint8_t * buf, uint16_t bufsize)
87
+ {
88
+ float * accel_buf = ( float *) buf ;
92
89
93
90
#if defined ARDUINO_NRF52840_CIRCUITPLAY
94
- temp = CircuitPlayground.temperature ();
91
+ accel_buf[0 ] = CircuitPlayground.motionX ();
92
+ accel_buf[1 ] = CircuitPlayground.motionY ();
93
+ accel_buf[2 ] = CircuitPlayground.motionZ ();
95
94
96
95
#elif defined ARDUINO_NRF52840_CLUE
97
- temp = bmp280.readTemperature ();
96
+
97
+ sensors_event_t accel, gyro, temp;
98
+ (void ) gyro; (void ) temp;
99
+
100
+ lsm6ds33.getEvent (&accel, &gyro, &temp);
101
+
102
+ accel_buf[0 ] = accel.acceleration .x ;
103
+ accel_buf[1 ] = accel.acceleration .y ;
104
+ accel_buf[2 ] = accel.acceleration .z ;
98
105
99
106
#endif
100
107
101
- memcpy (buf, &temp, 4 );
102
- return 4 ;
108
+ return 3 *sizeof (float ); // 12
103
109
}
104
110
105
111
uint16_t measure_light_sensor (uint8_t * buf, uint16_t bufsize)
106
- {
112
+ {
107
113
float lux;
108
114
109
115
#if defined ARDUINO_NRF52840_CIRCUITPLAY
@@ -119,29 +125,36 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
119
125
return 4 ;
120
126
}
121
127
122
- uint16_t measure_accel (uint8_t * buf, uint16_t bufsize)
123
- {
124
- float * accel_buf = (float *) buf;
128
+ uint16_t measure_gyro (uint8_t * buf, uint16_t bufsize)
129
+ {
125
130
126
- #if defined ARDUINO_NRF52840_CIRCUITPLAY
127
- accel_buf[0 ] = CircuitPlayground.motionX ();
128
- accel_buf[1 ] = CircuitPlayground.motionY ();
129
- accel_buf[2 ] = CircuitPlayground.motionZ ();
131
+ }
130
132
131
- #elif defined ARDUINO_NRF52840_CLUE
133
+ uint16_t measure_magnetic (uint8_t * buf, uint16_t bufsize)
134
+ {
132
135
133
- sensors_event_t accel, gyro, temp;
134
- (void ) gyro; (void ) temp;
136
+ }
135
137
136
- lsm6ds33.getEvent (&accel, &gyro, &temp);
138
+ uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
139
+ {
140
+ uint32_t button = 0 ;
137
141
138
- accel_buf[0 ] = accel.acceleration .x ;
139
- accel_buf[1 ] = accel.acceleration .y ;
140
- accel_buf[2 ] = accel.acceleration .z ;
142
+ #if defined ARDUINO_NRF52840_CIRCUITPLAY
143
+ button |= ( CircuitPlayground.slideSwitch () ? 0x01 : 0x00 );
144
+ button |= ( CircuitPlayground.leftButton () ? 0x02 : 0x00 );
145
+ button |= ( CircuitPlayground.rightButton () ? 0x04 : 0x00 );
146
+
147
+ #elif defined ARDUINO_NRF52840_CLUE
148
+ // Button is active LOW on most board except CPlay
149
+
150
+ // No slide switch
151
+ button |= ( digitalRead (PIN_BUTTON1) ? 0x00 : 0x02 );
152
+ button |= ( digitalRead (PIN_BUTTON2) ? 0x00 : 0x04 );
141
153
142
154
#endif
143
155
144
- return 3 *sizeof (float ); // 12
156
+ memcpy (buf, &button, 4 );
157
+ return 4 ;
145
158
}
146
159
147
160
void setup ()
@@ -215,6 +228,12 @@ void setup()
215
228
216
229
bleLight.begin ();
217
230
bleLight.setMeasureCallback (measure_light_sensor);
231
+
232
+ // bleGyro.begin();
233
+ // bleGyro.setMeasureCallback(measure_gyro);
234
+ //
235
+ // bleMagnetic.begin();
236
+ // bleMagnetic.setMeasureCallback(measure_magnetic);
218
237
219
238
bleButton.begin ();
220
239
bleButton.setMeasureCallback (measure_button);
0 commit comments