-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSWI2C_example.ino
More file actions
58 lines (40 loc) · 1.19 KB
/
SWI2C_example.ino
File metadata and controls
58 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* -----------------------------------------------------------------
SWI2C Library Example Sketch
https://github.com/Andy4495/SWI2C
MIT License
03/25/2018 - A.T. - Original
*/
/* -----------------------------------------------------------------
Periodically reads X and Z coordinates from the ZX sensor
-----------------------------------------------------------------
*/
#include "SWI2C.h"
#define SCL_PIN 9
#define SDA_PIN 10
// Constants
const uint8_t ZX_ADDR = 0x10; // ZX Sensor I2C address
const uint8_t ZPOS_REG = 0x0A;
const uint8_t XPOS_REG = 0x08;
const unsigned long delayTime = 1000;
uint8_t z_pos, x_pos;
unsigned long lastmilli;
SWI2C myZX = SWI2C(SDA_PIN, SCL_PIN, ZX_ADDR);
void setup() {
Serial.begin(9600);
myZX.begin();
Serial.println("SWI2C. Starting measurements...");
lastmilli = millis();
}
void loop() {
if ( (millis() - lastmilli) > delayTime) {
myZX.read1bFromRegister(ZPOS_REG, &z_pos);
myZX.read1bFromRegister(XPOS_REG, &x_pos);
Serial.print("Zpos: ");
Serial.println(z_pos);
Serial.print("Xpos: ");
Serial.println(x_pos);
Serial.print("Millis: ");
lastmilli = millis();
Serial.println(lastmilli);
}
}