Raw analog port read.
This node is different from analog read available in XOD. This Node do not divide read value by 1023. It deliver raw read values.
raw-analog-read
@/raw-analog-read
Raw analog port read.
This node is different from analog read available in XOD. This Node do not divide read value by 1023. It deliver raw read values.
PORTport
Analog port to read from. Should start with `A` to succeed.
UPDpulse
Triggers new read
DONEpulse
Fires on reading complete
VALnumber
The latest read value in range 0.0 … 1023
To use the node in your project you should have the garage-make-zone/ntc-thermistor library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
node {
// reading from analog input too frequently may affect WiFi connection on ESP8266
// see https://github.com/krzychb/EspScopeA0/tree/master/Bravo#results
#ifdef ESP8266
TimeMs lastReadTime = 0;
#endif
void evaluate(Context ctx) {
static_assert(isValidAnalogPort(constant_input_PORT), "must be a valid analog port");
if (!isInputDirty<input_UPD>(ctx))
return;
::pinMode(constant_input_PORT, INPUT);
#ifdef ESP8266
if (transactionTime() - lastReadTime > 4) {
lastReadTime = transactionTime();
emitValue<output_VAL>(ctx, ::analogRead(constant_input_PORT));
}
#else
emitValue<output_VAL>(ctx, ::analogRead(constant_input_PORT));
#endif
emitValue<output_DONE>(ctx, 1);
}
}