Skip to content

Commit c86c9f6

Browse files
Re-added example 1 file
Restructuring folders - should be fixed
1 parent 362e0cc commit c86c9f6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "SparkFun_STHS34PF80_Arduino_Library.h"
2+
#include <Wire.h>
3+
4+
STHS34PF80_I2C mySensor;
5+
6+
// Values to fill with presence and motion data
7+
int16_t presenceVal = 0;
8+
int16_t motionVal = 0;
9+
10+
11+
void setup()
12+
{
13+
Serial.begin(115200);
14+
Serial.println("STHS34PF80 Example 1: Basic Readings");
15+
16+
// Begin I2C
17+
if(Wire.begin() == false)
18+
{
19+
Serial.println("I2C Error - check I2C Address");
20+
while(1);
21+
}
22+
23+
// Establish communication with device
24+
if(mySensor.begin() == false)
25+
{
26+
Serial.println("Error setting up device - please check wiring.");
27+
while(1);
28+
}
29+
30+
delay(1000);
31+
}
32+
33+
void loop()
34+
{
35+
sths34pf80_tmos_drdy_status_t dataReady;
36+
mySensor.getDataReady(&dataReady);
37+
38+
// Check whether sensor has new data - run through loop if data is ready
39+
if(dataReady.drdy == 1)
40+
{
41+
sths34pf80_tmos_func_status_t status;
42+
mySensor.getStatus(&status);
43+
44+
// If presence flag is high, then print data
45+
if(status.pres_flag == 1)
46+
{
47+
// Presence Units: cm^-1
48+
mySensor.getPresenceValue(&presenceVal);
49+
Serial.print("Presence: ");
50+
Serial.println(presenceVal);
51+
}
52+
53+
if(status.mot_flag == 1)
54+
{
55+
Serial.println("Motion Detected!");
56+
}
57+
}
58+
59+
}
60+

0 commit comments

Comments
 (0)