1
- #include < Adafruit_Sensor.h>
2
1
#include < Adafruit_APDS9960.h>
3
2
#include < Adafruit_BMP280.h>
4
3
#include < Adafruit_LIS3MDL.h>
5
4
#include < Adafruit_LSM6DS33.h>
6
5
#include < Adafruit_SHT31.h>
6
+ #include < Adafruit_Sensor.h>
7
7
#include < PDM.h>
8
8
9
- Adafruit_APDS9960 apds9960; // proximity, light, color, gesture
10
- Adafruit_BMP280 bmp280; // temperautre, barometric pressure
11
- Adafruit_LIS3MDL lis3mdl; // magnetometer
12
- Adafruit_LSM6DS33 lsm6ds33; // accelerometer, gyroscope
13
- Adafruit_SHT31 sht30; // humidity
9
+ Adafruit_APDS9960 apds9960; // proximity, light, color, gesture
10
+ Adafruit_BMP280 bmp280; // temperautre, barometric pressure
11
+ Adafruit_LIS3MDL lis3mdl; // magnetometer
12
+ Adafruit_LSM6DS33 lsm6ds33; // accelerometer, gyroscope
13
+ Adafruit_SHT31 sht30; // humidity
14
14
15
15
uint8_t proximity;
16
16
uint16_t r, g, b, c;
@@ -25,14 +25,15 @@ extern PDMClass PDM;
25
25
short sampleBuffer[256 ]; // buffer to read samples into, each sample is 16-bits
26
26
volatile int samplesRead; // number of samples read
27
27
28
- void setup (void )
29
- {
28
+ void setup (void ) {
30
29
Serial.begin (115200 );
31
- // while (!Serial) delay(10);
30
+ // while (!Serial) delay(10);
32
31
Serial.println (" Feather Sense Sensor Demo" );
33
-
32
+
34
33
// initialize the sensors
35
- apds9960.begin (); apds9960.enableProximity (true ); apds9960.enableColor (true );
34
+ apds9960.begin ();
35
+ apds9960.enableProximity (true );
36
+ apds9960.enableColor (true );
36
37
bmp280.begin ();
37
38
lis3mdl.begin_I2C ();
38
39
lsm6ds33.begin_I2C ();
@@ -41,11 +42,9 @@ void setup(void)
41
42
PDM.begin (1 , 16000 );
42
43
}
43
44
44
-
45
- void loop (void )
46
- {
45
+ void loop (void ) {
47
46
proximity = apds9960.readProximity ();
48
- while (!apds9960.colorDataReady ()){
47
+ while (!apds9960.colorDataReady ()) {
49
48
delay (5 );
50
49
}
51
50
apds9960.getColorData (&r, &g, &b, &c);
@@ -74,28 +73,61 @@ void loop(void)
74
73
75
74
samplesRead = 0 ;
76
75
mic = getPDMwave (4000 );
77
-
76
+
78
77
Serial.println (" \n Feather Sense Sensor Demo" );
79
78
Serial.println (" ---------------------------------------------" );
80
- Serial.print (" Proximity: " ); Serial.println (apds9960.readProximity ());
81
- Serial.print (" Red: " ); Serial.print (r); Serial.print (" Green: " ); Serial.print (g); Serial.print (" Blue :" ); Serial.print (b); Serial.print (" Clear: " ); Serial.println (c);
82
- Serial.print (" Temperature: " ); Serial.print (temperature); Serial.println (" C" );
83
- Serial.print (" Barometric pressure: " ); Serial.println (pressure);
84
- Serial.print (" Altitude: " ); Serial.print (altitude); Serial.println (" m" );
85
- Serial.print (" Magnetic: " ); Serial.print (magnetic_x); Serial.print (" " ); Serial.print (magnetic_y); Serial.print (" " ); Serial.print (magnetic_z); Serial.println (" uTesla" );
86
- Serial.print (" Acceleration: " ); Serial.print (accel_x); Serial.print (" " ); Serial.print (accel_y); Serial.print (" " ); Serial.print (accel_z); Serial.println (" m/s^2" );
87
- Serial.print (" Gyro: " ); Serial.print (gyro_x); Serial.print (" " ); Serial.print (gyro_y); Serial.print (" " ); Serial.print (gyro_z); Serial.println (" dps" );
88
- Serial.print (" Humidity: " ); Serial.print (humidity); Serial.println (" %" );
89
- Serial.print (" Mic: " ); Serial.println (mic);
79
+ Serial.print (" Proximity: " );
80
+ Serial.println (apds9960.readProximity ());
81
+ Serial.print (" Red: " );
82
+ Serial.print (r);
83
+ Serial.print (" Green: " );
84
+ Serial.print (g);
85
+ Serial.print (" Blue :" );
86
+ Serial.print (b);
87
+ Serial.print (" Clear: " );
88
+ Serial.println (c);
89
+ Serial.print (" Temperature: " );
90
+ Serial.print (temperature);
91
+ Serial.println (" C" );
92
+ Serial.print (" Barometric pressure: " );
93
+ Serial.println (pressure);
94
+ Serial.print (" Altitude: " );
95
+ Serial.print (altitude);
96
+ Serial.println (" m" );
97
+ Serial.print (" Magnetic: " );
98
+ Serial.print (magnetic_x);
99
+ Serial.print (" " );
100
+ Serial.print (magnetic_y);
101
+ Serial.print (" " );
102
+ Serial.print (magnetic_z);
103
+ Serial.println (" uTesla" );
104
+ Serial.print (" Acceleration: " );
105
+ Serial.print (accel_x);
106
+ Serial.print (" " );
107
+ Serial.print (accel_y);
108
+ Serial.print (" " );
109
+ Serial.print (accel_z);
110
+ Serial.println (" m/s^2" );
111
+ Serial.print (" Gyro: " );
112
+ Serial.print (gyro_x);
113
+ Serial.print (" " );
114
+ Serial.print (gyro_y);
115
+ Serial.print (" " );
116
+ Serial.print (gyro_z);
117
+ Serial.println (" dps" );
118
+ Serial.print (" Humidity: " );
119
+ Serial.print (humidity);
120
+ Serial.println (" %" );
121
+ Serial.print (" Mic: " );
122
+ Serial.println (mic);
90
123
delay (300 );
91
124
}
92
125
93
-
94
126
/* ****************************************************************/
95
127
int32_t getPDMwave (int32_t samples) {
96
128
short minwave = 30000 ;
97
129
short maxwave = -30000 ;
98
-
130
+
99
131
while (samples > 0 ) {
100
132
if (!samplesRead) {
101
133
yield ();
@@ -109,7 +141,7 @@ int32_t getPDMwave(int32_t samples) {
109
141
// clear the read count
110
142
samplesRead = 0 ;
111
143
}
112
- return maxwave- minwave;
144
+ return maxwave - minwave;
113
145
}
114
146
115
147
void onPDMdata () {
0 commit comments