This library allows to read the analog input voltage on PINs 1, 3,7 &9 of the dice-IO.
It is based on the ADS1015_async library by Ton Rutgers.
To use this library
include "DICE_Analog.h"
By including this library the global object DICE_ANALOG_INPUTS
will be created. Call its begin() function to start the cyclic conversation of the values.
DICE_ANALOG_INPUTS.begin();
Now use the following methodes to read the current analog values of the PINs:
DICE_ANALOG_INPUTS.getPIN1Value();
DICE_ANALOG_INPUTS.getPIN3Value();
DICE_ANALOG_INPUTS.getPIN7Value();
DICE_ANALOG_INPUTS.getPIN9Value();
Returns
float: value of the current input voltage at the corresponding PIN
Example
void setup()
{
DICE_ANALOG_INPUTS.begin();
while(!Serial);
Serial.println("Analog input example");
}
void loop()
{
Serial.print("PIN1: " +
String(DICE_ANALOG_INPUTS.getPIN1Value(),3) + "V");
Serial.print("\tPIN3: " +
String(DICE_ANALOG_INPUTS.getPIN3Value(),3) + "V");
Serial.print("\tPIN7: " +
String(DICE_ANALOG_INPUTS.getPIN7Value(),3) + "V");
Serial.println("\tPIN9: " +
String(DICE_ANALOG_INPUTS.getPIN9Value(),3) + "V");
delay(200);
}
Note
Attention: Make sure not to apply voltages higher than UB to the analog inputs. The PIN1,3,7 & 9 of the dice-IO are digital outputs at the same time. Due to the embedded high side switch, voltages higher than UB would be ‘seen’ on the UB pin. Particularly if you use an USB (5V) supply for your tests, this would lead to damage of the USB port / hub it is connected to.
Find the examples in the Arduino IDE menu: File -> Examples -> DICE_Analog