nanoI2CSlaveExpander
ARDUINO Nano v3 used as I2C slace digital and analog io expander for ESP8266 and others...
nanoI2CIOExpLib.h
Go to the documentation of this file.
1 /**
2  @file nanoI2CIOExpLib.h
3  @author J.SORANZO
4  @date 05/01/2019
5  @copyright 2019 CC0
6  @version git versionning
7  @brief Header file of the class CNanoI2CIOExpander...
8 
9  @details This file doesn't instanciate any instance of this class. It is the user job...
10 */
11 #ifndef NANOI2CIOEXPANDER_H
12 #define NANOI2CIOEXPANDER_H
13 
14 
15 #define MAJVER 0x00
16 #define REGTEST1 0x01
17 #define REGTEST2 0x02
18 #define REGTEST3 0x03 // 0x55 (RO)
19 #define DDR 0x04 // DDR (R/W) 1 for output, default 0
20 #define DR 0x05 // digital DATA (R/W) a write on input bit has no effect
21 #define MINVER 0x06 // Minor version (RO)
22 #define PULLUP 0x07 // puulup reg (R/W) : 1 pullup is enable, default = 0
23 #define DDR2 0x08
24 #define DR2 0x09
25 #define PULLUP2 0x0A
26 
27 // 0x08 to 0x0F : reserved (read data 0xA5)
28 
29 
30 /**
31 * @class CNanoI2CIOExpander nanoI2CIOExpLib.h
32 * @brief A class to provide usual io functioon for nanoI2CIOExpander project...
33 
34 Functions provided are begin, pinMode, digitalRead, digitalWrite, analogRead
35 */
37 
38  public:
40  //begin can't be static because it uses registerRead().
41  void begin( int add = 0x5F );
42  void pinMode( int output, int mode );
43  int digitalRead( int input );
44  void digitalWrite( int output, int value );
45  int analogRead( int input);
46  static bool initOk;
47  bool test();
48 
49 
50  private:
51  int readRegister( int add );
52  void writeRegister( int add, int val);
53 };
54 
55 /**
56 * @class CFlasherNanoExp nanoI2CIOExpLib.h
57 * @brief a Class to flash a LED through nanoI2CIOExpander...
58  @details
59 This class is for flashing led with no delay function call with diffrents ton and toff
60 
61 In setup or elsewhere create a Flasher instance i and call i.begin( pin, ton, toff )
62 
63 Or begin( pin, ton, toff, repeat, period ) to flash n time in the period.
64 
65 reverseMode() can be used to inverse on and off times.
66 
67 They are no default values.
68 
69 In a loop call i.update();
70 
71 To return to led off and stop flashing you can call i.stop()
72 
73 i.getChangeStateCpt() can be used to flash a certain number of times
74 
75 to put LEd allways on or off call i.high() and i.low() method
76 */
78  public:
80  CFlasherNanoExp( int compAdd){ _componentAdd = compAdd; }
81  void begin( int pin, unsigned long ton, unsigned long toff);
82  void begin( int pin, unsigned long ton, unsigned long toff, int repeat, unsigned long period);
83  void update();
84  void reverseMode();
85  int getChangeStateCpt(){ return _changeStateCpt; }/**< @brief to stop flashing after a certain number of times*/
86  void stop();
87  void high();
88  void low();
89 
90  private:
91  CNanoI2CIOExpander _ioexp;
92  int _componentAdd = 0x5F;
93  unsigned long _ton;
94  unsigned long _toff;
95  unsigned long _period = 0;
96  int _repeat = 0;
97  int _repeatCount = 0;
98  int _pin;
99  unsigned long _previousMillis;
100  unsigned long _previousPeriod = 0;
101  int _ledState ;
102  unsigned long _changeStateCpt;
103  int _offLevel = 0;
104  int _onLevel = 1;
105  // bool _reverse = false;
106  bool _flashingMode = false;
107 };
108 
109 #endif
int getChangeStateCpt()
to stop flashing after a certain number of times
a Class to flash a LED through nanoI2CIOExpander...
void pinMode(int output, int mode)
A method to set the pinMode but...
int digitalRead(int input)
Well knonwn function digitalRead applie to nanoI2CIOExpander but...
void begin(int add=0x5F)
function that start the I2C protocol with nanoI2CIOExpander
void begin(int pin, unsigned long ton, unsigned long toff)
to prepare Led Flashing...
void reverseMode()
Reverse the mode when it should be off it is on and conversely.
void digitalWrite(int output, int value)
CFlasherNanoExp(int compAdd)
void low()
to put led allways at OFF state
int analogRead(int input)
A method tha return 10bits value of one of the 6 analog inputs...
void stop()
this function stop LED
void high()
to put led allways at ON state
bool test()
A special test method that use 2 special register to write and read and display on the Serial monitor...
void update()
This function should be call periodicly.
A class to provide usual io functioon for nanoI2CIOExpander project...