nanoI2CSlaveExpander
ARDUINO Nano v3 used as I2C slace digital and analog io expander for ESP8266 and others...
analogRead.ino
Go to the documentation of this file.
1 /**
2 * @file analogRead.ino
3 * @author J.Soranzo
4 * @date 5/01/2019
5 * @copyright 2019 CC0
6 * @version git_versionning
7 * @brief A analogRead to show of how to use the project nanoI2CIOExpander
8 */
9 
10 #include <nanoI2CIOExpLib.h>
11 
13 
14 void setup(){
15  Serial.begin(9600);
16  Serial.println( "Nano I2C IO Expander sample start.");
17  ioexp.begin();
18  Serial.println( "Init = " + String(CNanoI2CIOExpander::initOk?"ok":"ko") );
19  ioexp.test();
20 
21 }
22 #define QUANTUM 5.0/1024.0
23 #define ERROR 0.1059 //need to be adjsuted 11% between 0.2 and 4.5V
24 void loop(){
25  int analogVal;
26  float voltage;
27  analogVal = ioexp.analogRead( 0 );
28  Serial.print( "analog value = " + String(analogVal) );
29  voltage = (float)analogVal*QUANTUM*(1-ERROR);
30  // voltage = (float)analogVal*QUANTUM;
31  // voltage = QUANTUM;
32  Serial.println( ", analog voltage = " + String(voltage, 3) );
33  delay( 500);
34 }
void loop()
Definition: analogRead.ino:24
void setup()
Definition: analogRead.ino:14
#define ERROR
Definition: analogRead.ino:23
void begin(int add=0x5F)
function that start the I2C protocol with nanoI2CIOExpander
CNanoI2CIOExpander ioexp
Definition: analogRead.ino:12
Header file of the class CNanoI2CIOExpander...
int analogRead(int input)
A method tha return 10bits value of one of the 6 analog inputs...
#define QUANTUM
Definition: analogRead.ino:22
bool test()
A special test method that use 2 special register to write and read and display on the Serial monitor...
A class to provide usual io functioon for nanoI2CIOExpander project...