Analog Inputs and Outputs on an Ardbox Q Lite: full example
The Ardbox Q Lite reads a 0-10 V input and copies the value to a 0-10 V output.
What it does
The microcontroller reads input I0.4 (10 bits by default, 0 to 1023), scales it to 8 bits (0 to 255) and writes it to analog output A0.0. Works on the Ardbox Q Lite AD and ADR. On the AD, A0.0 shares its terminal with Q0.0: set the switch to analog.
What you need
- Ardbox Q Lite AD or ADR with a 12 to 24 Vdc supply.
- Arduino IDE 2.0+ with the Industrial Shields boards package (board: Ardbox Q, your version).
How to run it
- Upload 02-analog-io.ino with Arduino IDE.
- Apply 0 to 10 V on I0.4 and measure A0.0 with a multimeter.
02-analog-io.ino
/*
Ardbox Q Lite example 02: analog input to analog output
Reads the 0-10 V input I0.4 and copies it to the 0-10 V output A0.0.
Works on Ardbox Q Lite AD and ADR.
Analog inputs read 10 bits by default (0 to 1023).
Analog outputs write 8 bits by default (0 to 255).
On the AD, A0.0 shares its terminal with Q0.0: set the switch to analog.
*/
void setup() {
pinMode(A0_0, OUTPUT);
}
void loop() {
int raw = analogRead(I0_4); // 0 to 1023
int out = map(raw, 0, 1023, 0, 255); // 0 to 255
analogWrite(A0_0, out);
delay(20);
}