6) Implementing Outputs
The USB connection can also be used to run input and output
operations via the PC, which is particularly useful for testing or
troubleshooting purposes.
Initialize the serial connection with "Serial.begin()". Use the
transmission speed (baud rate) as the argument.
While the program is running, you need to start the output via
Tools/Serial Monitor
and set the desired baud rate (e.g. 57600).
The function "printSensors(500)" will then output the 9 values for
the sensors at the selected interval, e.g, every 500 ms.
At the beginning of the program, the usage of the serial
interface is defined by using "#define TEST".
If you no longer want to use serial output, you can comment
out the definition as follows: "//#define TEST."
Instead, in this example, the output is done using LEDs via
the "#else" operator, for instance.
By using "showShadows(500)", you can display on the 8 outer
blue LEDs whether the corresponding sensor values exceed the
threshold value of, for example, 500. In this case, the maximum
value of 1023 corresponds to a voltage of 5 V.
#include <VariAnt.h>
#define TEST
VariAnt ant;
void setup()
{
#ifdef TEST
Serial.begin(57600);
#endif
ant.setup();
}
void loop()
{
ant.update( );
#ifdef TEST
ant.printSensors(500);
#else
ant.showShadows(500);
#endif
}
Need help?
Do you have a question about the variAnt and is the answer not in the manual?