Update nano_c_mk1.ino
This commit is contained in:
parent
f78d086f6b
commit
96dc63afe1
|
@ -2,13 +2,13 @@
|
|||
|
||||
#define WAIT_TIME 1000UL // default wait time each value read
|
||||
#define ADS_MAX 4 // # of analog input pins of an ADS1115
|
||||
#define VOLTAGE_RANGE 6.144f // ADS1115 default gain (+/- 6.144V)
|
||||
#define VOLTAGE_RANGE 6.144f // ADS1115 default gain (+/- 6.144V). Change this number smaller will reduced its actual magnutude, and vice versa
|
||||
#define CONST_I2C 32768 // a constant value
|
||||
|
||||
unsigned long currTime; // non-blocking timer
|
||||
Adafruit_ADS1115 adc;
|
||||
int i; // loop iterators
|
||||
float adcReadings[ADS_MAX];
|
||||
float adcReadings[ADS_MAX]; // buffer to hold all values read from an adc
|
||||
|
||||
void setup() {
|
||||
Wire.begin();
|
||||
|
@ -18,12 +18,13 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
// TODO: The current reading is too slow for even the arduino's own ide's grapher cannot parse the data in time
|
||||
// TODO: The current reading is too slow beacuse `readADC_SingleEnded` is a blocking function. Not ideal on real-application.
|
||||
if (millis() - currTime >= WAIT_TIME) { // non-blocking time delay
|
||||
for (i = 0; i < ADS_MAX; i++) {
|
||||
adcReadings[i] = adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C;
|
||||
adcReadings[i] = adc.readADC_SingleEnded(i) * VOLTAGE_RANGE / CONST_I2C; // this part can just read the adc. The conversion part could done in the Python code for flexibility
|
||||
}
|
||||
Serial.print("[");
|
||||
// two seperate for loops for read adc and serial write to make it seems less laggy. again, this is completly wrong and need to replace it to something more non-blocking
|
||||
for (i = 0; i < ADS_MAX; i++) {
|
||||
Serial.print(adcReadings[i]);
|
||||
if (i != ADS_MAX - 1) {
|
||||
|
|
Loading…
Reference in New Issue