-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ADS_read_async.ino
75 lines (59 loc) · 1.23 KB
/
ADS_read_async.ino
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// FILE: ADS_read_async.ino
// AUTHOR: Rob.Tillaart
// PURPOSE: read analog inputs - asynchronous
// URL: https://github.com/RobTillaart/ADS1X15
// test
// connect 1 potmeter per port.
//
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).
//
#include "ADS1X15.h"
ADS1115 ADS(0x48);
float f = 0;
int16_t val_0;
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
delay(100);
Wire.begin();
Wire.setClock(100000);
ADS.begin();
ADS.setGain(0);
f = ADS.toVoltage(); // voltage factor
start = micros();
ADS.requestADC(0);
stop = micros();
Serial.println(stop - start);
delay(100);
while (ADS.isBusy());
start = micros();
val_0 = ADS.getValue();
stop = micros();
Serial.println(stop - start);
delay(100);
ADS.requestADC(0);
}
void loop()
{
if (ADS.isBusy() == false)
{
val_0 = ADS.getValue();
// request a new one
ADS.requestADC(0);
Serial.print("\tAnalog0: ");
Serial.print(val_0);
Serial.print('\t');
Serial.println(val_0 * f, 3);
}
// simulate other tasks...
delay(2000);
}
// -- END OF FILE --