diff --git a/README.md b/README.md index b06fae8..5c6e475 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Currently supported boards: - [I2C Encoder V2](https://github.com/Fattoresaimon/I2CEncoderV2) Library description [here](https://github.com/Fattoresaimon/ArduinoDuPPaLib/blob/master/examples/I2CEncoderV2/README.md) - [I2C NavKey](https://github.com/Fattoresaimon/I2CNavKey) Library description [here](https://github.com/Fattoresaimon/ArduinoDuPPaLib/blob/master/examples/I2CNavKey/README.md) +- [I2C Encoder Mini](https://github.com/Fattoresaimon/I2CEncoderMini) Library description [here](https://github.com/Fattoresaimon/ArduinoDuPPaLib/blob/master/examples/I2CEncoderMini/README.md) diff --git a/examples/I2CEncoderMini/Basic_with_Callbacks/Basic_with_Callbacks.ino b/examples/I2CEncoderMini/Basic_with_Callbacks/Basic_with_Callbacks.ino new file mode 100644 index 0000000..d7154a5 --- /dev/null +++ b/examples/I2CEncoderMini/Basic_with_Callbacks/Basic_with_Callbacks.ino @@ -0,0 +1,101 @@ +#include +#include + +/*This is a basic example for using the I2C Encoder mini + The counter is set to work between +10 to -10, at every encoder click the counter value is printed on the terminal. + It's also printet when the push button is pressed, or released or double pushed. + The callback are used instead of the switch case + + Connections with Arduino UNO: + - -> GND + + -> 5V + SDA -> A4 + SCL -> A5 + INT -> A3 +*/ + +const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board */ +//Class initialization with the I2C addresses +i2cEncoderMiniLib Encoder(0x20); /* A0 is soldered */ + +//Callback when the CVAL is incremented +void encoder_increment(i2cEncoderMiniLib* obj) { + Serial.print("Increment: "); + Serial.println(Encoder.readCounterByte()); +} + +//Callback when the CVAL is decremented +void encoder_decrement(i2cEncoderMiniLib* obj) { + Serial.print("Decrement: "); + Serial.println(Encoder.readCounterByte()); +} + +//Callback when CVAL reach MAX +void encoder_max(i2cEncoderMiniLib* obj) { + Serial.print("Maximum threshold: "); + Serial.println(Encoder.readCounterByte()); +} + +//Callback when CVAL reach MIN +void encoder_min(i2cEncoderMiniLib* obj) { + Serial.print("Minimum threshold: "); + Serial.println(Encoder.readCounterByte()); +} + +//Callback when the encoder is pushed +void encoder_push(i2cEncoderMiniLib* obj) { + Serial.println("Encoder is pushed!"); +} + +//Callback when the encoder is released +void encoder_released(i2cEncoderMiniLib* obj) { + Serial.println("Encoder is released"); +} + +//Callback when the encoder is double pushed +void encoder_double_push(i2cEncoderMiniLib* obj) { + Serial.println("Encoder is double pushed!"); +} + +//Callback when the encoder is long pushed +void encoder_long_push(i2cEncoderMiniLib* obj) { + Serial.println("Encoder is long pushed!"); +} + +void setup(void) { + pinMode(IntPin, INPUT); + Wire.begin(); + Serial.begin(115200); + Serial.println("**** I2C Encoder Mini basic example ****"); + Encoder.reset(); + Encoder.begin(i2cEncoderMiniLib::WRAP_DISABLE + | i2cEncoderMiniLib::DIRE_LEFT | i2cEncoderMiniLib::IPUP_ENABLE + | i2cEncoderMiniLib::RMOD_X1 ); + + Encoder.writeCounter((int32_t) 0); /* Reset the counter value */ + Encoder.writeMax((int32_t) 10); /* Set the maximum threshold*/ + Encoder.writeMin((int32_t) - 10); /* Set the minimum threshold */ + Encoder.writeStep((int32_t) 1); /* Set the step to 1*/ + Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */ + + // Definition of the events + Encoder.onIncrement = encoder_increment; + Encoder.onDecrement = encoder_decrement; + Encoder.onMax = encoder_max; + Encoder.onMin = encoder_min; + Encoder.onButtonPush = encoder_push; + Encoder.onButtonRelease = encoder_released; + Encoder.onButtonDoublePush = encoder_double_push; + Encoder.onButtonLongPush = encoder_long_push; + + /* Enable the I2C Encoder V2 interrupts according to the previus attached callback */ + Encoder.autoconfigInterrupt(); + +} + +void loop() { + if (digitalRead(IntPin) == LOW) { + /* Check the status of the encoder and call the callback */ + Encoder.updateStatus(); + } +} diff --git a/examples/I2CEncoderMini/Change_Address/Change_Address.ino b/examples/I2CEncoderMini/Change_Address/Change_Address.ino new file mode 100644 index 0000000..66bc810 --- /dev/null +++ b/examples/I2CEncoderMini/Change_Address/Change_Address.ino @@ -0,0 +1,215 @@ +#include +#include + +/* This example is used for change the address of the I2C Encoder Mini + Connections with Arduino UNO: + - -> GND + + -> 5V + SDA -> A4 + SCL -> A5 + + The COM boudrate is 115200. + You can use the command 'S' for find the I2C encoder mini on the I2C bus. + Or you can write directly the address in decimal or hexadecimal. + After after you need to write the new address in the same way. + Example: + + **** I2C Encoder Address changer! **** + All the devices must have different address! + Avaiable commands: + S: for searching the I2C encoder mini + 0xXX or XXX: Address of the target device in hex or decimal + + S + + Scanning.... + I2C Encoder mini found at 33 ( 0x21 ) !! + + + All the devices must have different address! + Avaiable commands: + S: for searching the I2C encoder mini + 0xXX or XXX: Address of the target device in hex or decimal + + 0x21 + + Insert the desired address in hex or decimal: + + 24 + + Changing address from 33 ( 0x21 ) to 24 ( 0x18 ) + Address Changed! + +*/ + +void ChangeAddress(uint8_t add); +int8_t NewAdd(void); +int8_t CommadParser(void); +int8_t NumberParser(char buff[]); +bool CommandRead(void); +void Search(void); +void PrintHEX(uint8_t i); + +i2cEncoderMiniLib Encoder(0x20); + + +char c_buff[5] = {0}; +uint8_t c_buff_cnt = 0; + +int8_t t_add; + + +void setup(void) { + Wire.begin(); + Serial.begin(115200); + Serial.println("\n\n**** I2C Encoder Address changer! ****"); +} + +void loop() { + Serial.println("All the devices must have different address!"); + Serial.println("Avaiable commands:"); + Serial.println(" S: for searching the I2C encoder mini"); + Serial.println(" 0xXX or XXX: Address of the target device in hex or decimal\n"); + + t_add = CommadParser(); + if (t_add <= 0) { + switch (t_add) { + case -1: + Serial.println("Wrong address range!"); + break; + + case -2: + Serial.println("Wrong command!"); + break; + + case -3: + Search(); + break; + } + } else { + Encoder.address = t_add; + if (Encoder.readIDCode() == 0x39) { + Serial.println("Insert the desired address in hex or decimal: "); + t_add = NewAdd(); + if (t_add <= 0) { + Serial.println("Incorrect Address!"); + } else { + ChangeAddress(t_add); + } + } else { + Serial.println("No device at that address!"); + } + } + Serial.print("\n\n"); +} + + +void ChangeAddress(uint8_t add) { + Serial.print("Changing address from "); + Serial.print(Encoder.address); + Serial.print(" ( "); + PrintHEX(Encoder.address); + Serial.print(" ) to "); + Serial.print(add); + Serial.print(" ( "); + PrintHEX(add); + Serial.println(" )"); + Encoder.ChangeI2CAddress(add); + // delay(1000); + Encoder.reset(); + Encoder.address = add; + if (Encoder.readIDCode() == 0x39) { + Serial.println("Address Changed!"); + } else { + Serial.println("Error in changing address!"); + } +} + + +int8_t NewAdd(void) { + + if (CommandRead() == true) { + return (NumberParser(c_buff)); + } else { + return -1; + } +} + + +int8_t CommadParser(void) { + + if (CommandRead() == true) { + if ( c_buff[0] == 'S' && c_buff[1] == '\n') { + return -3; + } + return (NumberParser(c_buff)); + } else { + return -2; + } +} + + +int8_t NumberParser(char buff[]) { + int8_t temp; + if ( buff[0] == '0' && buff[1] == 'x') { + temp = (int8_t)strtol(buff, NULL, 16); + } else { + temp = (int8_t)strtol(buff, NULL, 10); + } + + if (temp <= 0) { + return -1; + } else { + return temp; + } + +} + + +bool CommandRead(void) { + c_buff_cnt = 0; + while(Serial. read() >= 0); + while (c_buff_cnt < 5) { + if (Serial.available()) { + char inChar = (char)Serial.read(); + c_buff[c_buff_cnt] = inChar; + c_buff_cnt++; + if (inChar == '\n') + return true; + } + } + return false; +} + + +void Search(void) { + uint8_t i, error; + Serial.println("Scanning...."); + for (i = 0; i < 0x80; i++ ) + { + Wire.beginTransmission(i); + error = Wire.endTransmission(); + + if (error == 0) + { + Encoder.address = i; + if (Encoder.readIDCode() == 0x39) { + Serial.print("I2C Encoder mini found at "); + Serial.print(Encoder.address); + Serial.print(" ( "); + PrintHEX(Encoder.address); + Serial.print(" )"); + Serial.println(" !!"); + } + } + + } +} + + +void PrintHEX(uint8_t i) { + Serial.print("0x"); + if (i < 16) + Serial.print("0"); + Serial.print(i, HEX); +} diff --git a/examples/I2CEncoderMini/README.md b/examples/I2CEncoderMini/README.md new file mode 100644 index 0000000..fa7637e --- /dev/null +++ b/examples/I2CEncoderMini/README.md @@ -0,0 +1,338 @@ +# I2C Encoder Mini Arduino Library +-------------------------------------------------------------------------------- + +## Introduction + +Here you can find the library description of the [I2C Encoder Mini](https://github.com/Fattoresaimon/I2CEncoderMini) for the Arduino IDE. +For more details of the functionality of the board, please read the Datasheet on GitHub + +The I2C Encoder Mini is available on [Tindie!](https://www.tindie.com/products/saimon/i2c-encoder-mini/) + +## Initialization of the class + +The library makes available the class **i2cEncoderMiniLib** +To initialize the library, you have to declare an instance of the class **i2cEncoderMiniLib** for each encoders. +For example: + +``` C++ +i2cEncoderMiniLib encoder(0x30); +``` +Declaration of one encoder with the address 0x30. The jumper A4 and A5 are shorted. + +``` C++ +i2cEncoderMiniLib encoder(0b0110000); +``` +Declaration of the same encoder but in binary format. + +```C++ +i2cEncoderMiniLib encoder1(0x30); +i2cEncoderMiniLib encoder2(0x32); +``` +Declaration of two encoders with the address 0x30 and 0x34 in two separated variable. + +```C++ +i2cEncoderMiniLib encoder[2] = { i2cEncoderMiniLib(0x30), i2cEncoderMiniLib(0x34)}; +``` +Declaration of an array of the two encoders with the address 0x30 and 0x34. + +## Parameters + +Each class has also a public variable called **id** that is used for setting a custom id to each class. + +```C++ +i2cEncoderMiniLib encoder(0x30); +encoder.id=1 +``` +The **id** can be useful when you declare an array of i2cEncoderMiniLib class. The **id** can be used as a index in the loops. + +## Callback Configuration + +This library support the callback functionality. +There is the possibility to link a function to a specific interrupt of the I2C Encoder V2, in this way the function is automatically called when the I2C Encoder V2 generates an interrupts. + +A callback function must be declared as the following: + +```C++ +void NAME_OF_THE_FUNCTION(i2cEncoderMiniLib* obj) +``` + +The argument **i2cEncoderMiniLib* obj** is the pointer to the class that called the method. + +There are 16 possible events: + +| Event | Description | +|:-----------:|:----------------------------------| +| onButtonRelease | Encoder push button is released | +| onButtonPush | Encoder push button is pushed | +| onButtonDoublePush | Encoder push button is double pushed | +| onButtonLongPush | Encoder push button is long press| +| onIncrement | The counter value is incremented | +| onDecrement | The counter value is decremented | +| onChange | The counter value is incremented or decremented | +| onMax | The counter value reach the maximum threshold | +| onMin | The counter value reach the minimum threshold | +| onMinMax | The counter value reach the maximum or minimum threshold | + + +#### Examples: + +```C++ +i2cEncoderMiniLib Encoder(0x61); // Class declaration + +... + +// Simple callback that ist's called when the encoder is rotated +void encoder_change(i2cEncoderMiniLib* obj) { + Serial.println( obj->readCounterByte()); //Print on the terminal the counter value. +} + +... + +Encoder.onChange = encoder_change; //Attach the event to the callback function. + +} + +``` + +If you need to remove the link with a callback, you just need to define: +```C++ +Encoder.onChange=NULL; +``` + +## Initialization +### void begin( uint16_t conf) +This is used for initializing the encoder by writing the configuration register of the encoder. +The parameters can be concatenated in OR mode. +The possible parameters are the following: + +| Parameter | Description | +| ---------- | ------------------------------------------------------ | +| WRAP_ENABLE | Wrap enable. When the counter value reaches the CMAX+1, restart to the CMIN and vice versa | +| WRAP_DISABLE | Wrap disable. When the counter value reaches the CMAX or CMIN, the counter stops to increasing or decreasing | +| | | +| DIRE_LEFT | Rotate left side to increase the value counter | +| DIRE_RIGHT | Rotate right side to increase the value counter | +| | | +| IPUP_DISABLE | Disable the internal pull-up on the INT pin | +| IPUP_ENABLE | Enable the internal pull-up on the INT pin | +| | | +| RMOD_X4 | Encoder in X4 mode | +| RMOD_X2 | Encoder in X2 mode | +| RMOD_X1 | Encoder in X1 mode | +| | | +| RESET | Reset the board | + + + +#### Examples: + +```C++ +encoder.begin(i2cEncoderMiniLib::WRAP_DISABLE | i2cEncoderMiniLib::DIRE_LEFT | i2cEncoderMiniLib::IPUP_ENABLE | i2cEncoderMiniLib::RMOD_X1 ); +``` + +Please remember to add the class name **i2cEncoderMiniLib::** before the parameter! + +### void reset(void) + +Reset of the board. +In this command there is 10ms delay in order to make the board correctly restart. + + + +## Configuration + +### void writeInterruptConfig(uint8_t interrupt) + +This method is used for enabling or disabling the interrupt source selectively. When an interrupt event occurs, the INT pin goes low and the event is stored in the status register. + +| Parameter | Description | +|:-----------:|:-------------:| +| PUSHR | Push button of the encoder is released | +| PUSHP | Push button of the encoder is pressed | +| PUSHD | Push button of the encoder is doule pushed | +| RINC | Encoder is rotated in the increment direction | +| RDEC | Encoder is rotated in the decrement direction | +| RMAX | Maximum threshold is reached | +| RMIN | Minimum threshold is reached | +| INT_2 | An event on the interrupt 2 register occurs | + +#### Examples: + +```C++ + Encoder.writeInterruptConfig(i2cEncoderMiniLib::INT_2 | i2cEncoderMiniLib::RMIN | i2cEncoderMiniLib::RMAX | i2cEncoderMiniLib::RDEC | i2cEncoderMiniLib::RINC | i2cEncoderMiniLib::PUSHR); +``` + +Please remember to add the class name **i2cEncoderMiniLib::** before the parameter! + +### void autoconfigInterrupt(void) + +This method auto configures the **INTCONF** register according to the attached callback. +**For the proper use, must be called after the definition of the last event property.** + +```C++ + Encoder.onIncrement = encoder_increment; + Encoder.onDecrement = encoder_decrement; + Encoder.onMax = encoder_max; + Encoder.onMin = encoder_min; + Encoder.onButtonPush = encoder_push; + Encoder.onButtonRelease = encoder_released; + Encoder.onButtonDoublePush = encoder_double_push; + /* Enable the I2C Encoder V2 interrupts according to the previus attached callback */ + Encoder.autoconfigInterrupt(); + +``` + +### void writeDoublePushPeriod(uint8_t dperiod) + +This method is used for setting the window period **DPPERIOD** of the double push of the rotary encoder switch. When the value is 0, the double push option is disabled. +The I2C encoder V2 will multiplies this value by 10 (value x10). + +#### Examples: + +```C++ +encoder.writeDoublePushPeriod(50); //Set a period for the double push of 500ms +``` + +### void ChangeI2CAddress(uint8_t add) +This methods is used to change the I2C address of the device. +The changes will have effect after a reset or a power cycle of the board. + +**Pay attention with this command, it's not reversible!** + + +## Status + +### bool updateStatus(void) +Read from the encoder status register **ESTATUS** and save the value internally. +Return value is **true** in case of some event, otherwise is **false** +In case an event of the I2STATUS register, the I2STATUS is automatically be read. + +#### Examples: + +```C++ + if ( Encoder.updateStatus() == true) { + // Something happens + } +``` + +### bool readStatus(Int_Status s) +Must be called after **updateStatus()**, this method is used for checking if some event occurs on the **ESTATUS** register. +Return value is **true** in case of the event occured, otherwise is **false** +Possible parameters are: + +| Parameter | Description | +|:-----------:|:-------------:| +| PUSHR | Push button of the encoder is released | +| PUSHP | Push button of the encoder is pressed | +| PUSHD | Push button of the encoder is doule pushed | +| RINC | Encoder is rotated in the increment direction | +| RDEC | Encoder is rotated in the decrement direction | +| RMAX | Maximum threshold is reached | +| RMIN | Minimum threshold is reached | +| INT2 | An event on the interrupt 2 register occurs | + +#### Example: +```C++ + if ( Encoder.updateStatus() == true) { + if ( Encoder.readStatus(i2cEncoderMiniLib::RINC)) { + Serial.print("Increment "); + } + if ( Encoder.readStatus(i2cEncoderMiniLib::RDEC)) { + Serial.print("Decrement "); + } + + if ( Encoder.readStatus(i2cEncoderMiniLib::RMAX)) { + Serial.print("Maximum threshold: "); + } + + if ( Encoder.readStatus(i2cEncoderMiniLib::RMIN)) { + Serial.print("Minimum threshold: "); + } + + if ( Encoder.readStatus(i2cEncoderMiniLib::PUSHR)) { + Serial.println("Push button Released"); + } + + if ( Encoder.readStatus(i2cEncoderMiniLib::PUSHP)) { + } + + if ( Encoder.readStatus(i2cEncoderMiniLib::PUSHD)) { + Serial.println("Double push!"); + } +``` + +Please remember to add the class name **i2cEncoderMiniLib::** before the parameter! + +### uint8_t readStatus(void) +Return the status of the register **ESTATUS** + + + +## Reading methods + +### int32_t readCounterLong(void) +Return the counter value in the format **int32_t**, by reading all the 4 bytes of the counter value registers. + +### int16_t readCounterInt(void) +Return the counter value in the format **int16_t**, by reading the 2 LSB of the counter value registers. +Useful when the counter register is between the values -32768 to 32767. + +### int8_t readCounterByte(void) +Return the counter value in the format **int8_t**, by reading the LSB byte of the counter value register. +Useful when the counter register is between the values -128 to 127 + + +### int32_t readMax(void) +Return the maximum threshold in format **int32_t**, bye reading all the 4 bytes of the counter Max. + + +### int32_t readMin(void) +Return the minimum threshold in format **int32_t**, by reading all the 4 byte of the counter Min. + + +### int32_t readStep(void) +Return the minimum threshold in format **int32_t**, by reading all the 4 bytes of the ISTEP registers. + +### uint8_t readDoublePushPeriod(void) +Return the value of the DPPERIOD register. + +### uint8_t readIDCode(uint8_t add) +Return the ID code of the I2C Encoder V2.1, that is 0x53 +Avaiable only on the V2.1 + +### uint8_t readVersion(uint8_t add) +Return the version of the board. +Avaiable only on the V2.1 + +### uint8_t readEEPROM(uint8_t add) +Return the value of the EEPROM register. +This function automatically manage the setting of the first and second memory bank. + + +## Writing methods + +### void writeCounter(int32_t counter) +Write the counter value register with a **int32_t** number. All of the 4 bytes are wrote. + +### void writeCounter(float counter) +Write the counter value register with a **float** number. All of the 4 bytes are wrote. + +### void writeMax(int32_t max) +Write the Max register with a **int32_t** number. All of the 4 bytes are wrote. + +### void writeMin(int32_t min) +Write the Min register with a **int32_t** number. All of the 4 bytes are wrote. + +### void writeStep(int32_t step) +Write the increment step with a **int32_t** number. All of the 4 bytes are wrote. + +### void writeDoublePushPeriod(uint8_t dperiod) +Write the DPPERIOD register. + + +### void writeEEPROM(uint8_t add, uint8_t data) +Write the EEPROM memory. +The input parameter *add* is the address. +The input parameter *data* is the data that will be written. + + diff --git a/keywords.txt b/keywords.txt index d42650e..8c8804d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -72,7 +72,9 @@ writeGammaBLED KEYWORD2 writeGammaGP1 KEYWORD2 writeGammaGP2 KEYWORD2 writeGammaGP3 KEYWORD2 - +readIDCode KEYWORD2 +readVersion KEYWORD2 +ChangeI2CAddress KEYWORD2 ####################################### # Constants (LITERAL1) @@ -107,6 +109,7 @@ onLeftRelease LITERAL1 onCentralPush LITERAL1 onCentralRelease LITERAL1 onCentralDoublePush LITERAL1 +onButtonLongPush LITERAL1 GP_PWM LITERAL1 GP_OUT LITERAL1 GP_AN LITERAL1 @@ -146,6 +149,7 @@ DIRE_LEFT LITERAL1 DIRE_RIGHT LITERAL1 IPUP_DISABLE LITERAL1 IPUP_ENABLE LITERAL1 +RMOD_X4 LITERAL1 RMOD_X2 LITERAL1 RMOD_X1 LITERAL1 RGB_ENCODER LITERAL1 diff --git a/src/i2cEncoderMiniLib.cpp b/src/i2cEncoderMiniLib.cpp index 43c1f57..9c3ceb3 100644 --- a/src/i2cEncoderMiniLib.cpp +++ b/src/i2cEncoderMiniLib.cpp @@ -18,7 +18,7 @@ /*********************************** Public functions *************************************/ /** Class costructor **/ i2cEncoderMiniLib::i2cEncoderMiniLib(uint8_t add) { - _add = add; + address = add; } /** Used for initialize the I2C Encoder Mini **/ @@ -231,6 +231,7 @@ void i2cEncoderMiniLib::ChangeI2CAddress(uint8_t add) { writeEncoder(REG_I2CADDRESS, add); writeEncoder(REG_I2CADDRESS, add); writeEncoder(REG_I2CADDRESS, add); + delay(100); } /** Write the EEPROM memory**/ @@ -247,10 +248,10 @@ void i2cEncoderMiniLib::writeEEPROM(uint8_t add, uint8_t data) { uint8_t i2cEncoderMiniLib::readEncoderByte(uint8_t reg) { byte rdata = 0xFF; - Wire.beginTransmission(_add); + Wire.beginTransmission(address); Wire.write(reg); Wire.endTransmission(); - Wire.requestFrom(_add, (uint8_t) 1); + Wire.requestFrom(address, (uint8_t) 1); if (Wire.available()) { rdata = Wire.read(); } @@ -259,10 +260,10 @@ uint8_t i2cEncoderMiniLib::readEncoderByte(uint8_t reg) { /** Read 2 bytes from the encoder **/ int16_t i2cEncoderMiniLib::readEncoderInt(uint8_t reg) { - Wire.beginTransmission(_add); + Wire.beginTransmission(address); Wire.write(reg); Wire.endTransmission(); - Wire.requestFrom(_add, (uint8_t) 4); + Wire.requestFrom(address, (uint8_t) 4); if (Wire.available()) { _tem_data.bval[1] = Wire.read(); _tem_data.bval[0] = Wire.read(); @@ -273,10 +274,10 @@ int16_t i2cEncoderMiniLib::readEncoderInt(uint8_t reg) { /** Read 4 bytes from the encoder **/ int32_t i2cEncoderMiniLib::readEncoderLong(uint8_t reg) { - Wire.beginTransmission(_add); + Wire.beginTransmission(address); Wire.write(reg); Wire.endTransmission(); - Wire.requestFrom(_add, (uint8_t) 4); + Wire.requestFrom(address, (uint8_t) 4); if (Wire.available()) { _tem_data.bval[3] = Wire.read(); _tem_data.bval[2] = Wire.read(); @@ -290,7 +291,7 @@ int32_t i2cEncoderMiniLib::readEncoderLong(uint8_t reg) { /** Send to the encoder 1 byte **/ void i2cEncoderMiniLib::writeEncoder(uint8_t reg, uint8_t data) { - Wire.beginTransmission(_add); + Wire.beginTransmission(address); Wire.write(reg); Wire.write(data); Wire.endTransmission(); @@ -304,7 +305,7 @@ void i2cEncoderMiniLib::writeEncoder(uint8_t reg, int32_t data) { temp[1] = _tem_data.bval[2]; temp[2] = _tem_data.bval[1]; temp[3] = _tem_data.bval[0]; - Wire.beginTransmission(_add); + Wire.beginTransmission(address); Wire.write(reg); Wire.write(temp, (uint8_t) 4); Wire.endTransmission(); diff --git a/src/i2cEncoderMiniLib.h b/src/i2cEncoderMiniLib.h index efba2e9..d172263 100644 --- a/src/i2cEncoderMiniLib.h +++ b/src/i2cEncoderMiniLib.h @@ -87,6 +87,7 @@ class i2cEncoderMiniLib { }; uint8_t id = 0x00; + uint8_t address = 0x00; typedef void (*Callback)(i2cEncoderMiniLib*); /* Event */ @@ -151,7 +152,7 @@ class i2cEncoderMiniLib { private: - uint8_t _add = 0x00; + uint8_t _stat = 0x00; uint8_t _gconf = 0x00; union Data_v _tem_data;