Skip to content

Commit

Permalink
I2CEncoderV2 enum redefinition
Browse files Browse the repository at this point in the history
Moved the enum inside of the I2CEncoderV2  class.
  • Loading branch information
Fattoresaimon committed Mar 25, 2019
1 parent 6284277 commit 1862fc3
Show file tree
Hide file tree
Showing 13 changed files with 643 additions and 668 deletions.
63 changes: 32 additions & 31 deletions examples/I2CEncoderV2/Basic/Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,87 +16,88 @@

const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board /*
//Class initialization with the I2C addresses*/
i2cEncoderLibV2 Encoder(0x61); /* A0 is solderedA */
i2cEncoderLibV2 Encoder(0x01); /* A0 is soldered */


void setup(void)
{
void setup(void) {
pinMode(IntPin, INPUT);
Wire.begin();
Serial.begin(115200);
Serial.println("**** I2C Encoder V2 basic example ****");
/*
INT_DATA= The register are considered integer.
WRAP_DISABLE= The WRAP option is disabled
DIRE_LEFT= Encoder left direction increase the value
IPUP_ENABLE= INT pin have the pull-up enabled.
RMOD_X1= Encoder configured as X1.
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
INT_DATA= The register are considered integer.
WRAP_DISABLE= The WRAP option is disabled
DIRE_LEFT= Encoder left direction increase the value
IPUP_ENABLE= INT pin have the pull-up enabled.
RMOD_X1= Encoder configured as X1.
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
*/
Encoder.reset();
Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!

Encoder.writeCounter((int32_t)0); /* Reset the counter value */
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
Encoder.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE
| i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!

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.writeStep((int32_t) 1); /* Set the step to 1*/
Encoder.writeInterruptConfig(0xff); /* Enable all the interrupt */
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
}

void loop() {

if (digitalRead(IntPin) == LOW) {
if ( Encoder.updateStatus()) {
if ( Encoder.readStatus(RINC)) {
if (Encoder.updateStatus()) {
if (Encoder.readStatus(i2cEncoderLibV2::RINC)) {
Serial.print("Increment: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());

/* Write here your code */

}
if ( Encoder.readStatus(RDEC)) {
if (Encoder.readStatus(i2cEncoderLibV2::RDEC)) {
Serial.print("Decrement: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());

/* Write here your code */

}

if ( Encoder.readStatus(RMAX)) {
if (Encoder.readStatus(i2cEncoderLibV2::RMAX)) {
Serial.print("Maximum threshold: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());

/* Write here your code */

}

if ( Encoder.readStatus(RMIN)) {
if (Encoder.readStatus(i2cEncoderLibV2::RMIN)) {
Serial.print("Minimum threshold: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());

/* Write here your code */

}

if ( Encoder.readStatus(PUSHR)) {
if (Encoder.readStatus(i2cEncoderLibV2::PUSHR)) {
Serial.println("Push button Released");

/* Write here your code */

}

if ( Encoder.readStatus(PUSHP)) {
if (Encoder.readStatus(i2cEncoderLibV2::PUSHP)) {
Serial.println("Push button Pressed");

/* Write here your code */

}

if ( Encoder.readStatus(PUSHD)) {
if (Encoder.readStatus(i2cEncoderLibV2::PUSHD)) {
Serial.println("Double push!");

/* Write here your code */
Expand Down
72 changes: 28 additions & 44 deletions examples/I2CEncoderV2/Basic_with_Callbacks/Basic_with_Callbacks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,91 +16,75 @@

const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board */
//Class initialization with the I2C addresses
i2cEncoderLibV2 Encoder(0x61); /* A0 is soldered */

i2cEncoderLibV2 Encoder(0x01); /* A0 is soldered */

//Callback when the CVAL is incremented
void encoder_increment(i2cEncoderLibV2* obj) {
Serial.print("Increment: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());
}



//Callback when the CVAL is decremented
void encoder_decrement(i2cEncoderLibV2* obj) {
Serial.print("Decrement: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());
}



//Callback when CVAL reach MAX
void encoder_max(i2cEncoderLibV2* obj) {
Serial.print("Maximum threshold: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());
}




//Callback when CVAL reach MIN
void encoder_min(i2cEncoderLibV2* obj) {
Serial.print("Minimum threshold: ");
Serial.println( Encoder.readCounterByte());
Serial.println(Encoder.readCounterByte());
}




//Callback when the encoder is pushed
void encoder_push(i2cEncoderLibV2* obj) {
Serial.println("Encoder is pushed!");
}



//Callback when the encoder is released
void encoder_released(i2cEncoderLibV2* obj) {
Serial.println("Encoder is released");
}



//Callback when the encoder is double pushed
void encoder_double_push(i2cEncoderLibV2* obj) {
Serial.println("Encoder is double pushed!");
}




void setup(void)
{
void setup(void) {
pinMode(IntPin, INPUT);
Wire.begin();
Serial.begin(115200);
Serial.println("**** I2C Encoder V2 basic example ****");
/*
INT_DATA= The register are considered integer.
WRAP_DISABLE= The WRAP option is disabled
DIRE_LEFT= Encoder left direction increase the value
IPUP_ENABLE= INT pin have the pull-up enabled.
RMOD_X1= Encoder configured as X1.
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
INT_DATA= The register are considered integer.
WRAP_DISABLE= The WRAP option is disabled
DIRE_LEFT= Encoder left direction increase the value
IPUP_ENABLE= INT pin have the pull-up enabled.
RMOD_X1= Encoder configured as X1.
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
*/
Encoder.reset();
Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!

Encoder.writeCounter((int32_t)0); /* Reset the counter value */
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
Encoder.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE
| i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!

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.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
Encoder.writeStep((int32_t) 1); /* Set the step to 1*/
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */

// Definition of the events
Encoder.onIncrement = encoder_increment;
Encoder.onDecrement = encoder_decrement;
Expand All @@ -109,9 +93,9 @@ void setup(void)
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();
Encoder.autoconfigInterrupt();

}

Expand All @@ -120,4 +104,4 @@ void loop() {
/* Check the status of the encoder and call the callback */
Encoder.updateStatus();
}
}
}
10 changes: 5 additions & 5 deletions examples/I2CEncoderV2/ESP32_RGB_encoder/ESP32_RGB_encoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ i2cEncoderLibV2 Encoder(0b1100001); /* For make the address 0x61 only the jumper

//Callback when the encoder is rotated
void encoder_rotated(i2cEncoderLibV2* obj) {
if ( obj->readStatus( RINC))
if ( obj->readStatus( i2cEncoderLibV2::RINC))
Serial.print("Increment: ");
else
Serial.print("Decrement: ");
Expand All @@ -40,7 +40,7 @@ void encoder_click(i2cEncoderLibV2* obj) {

//Callback when the encoder reach the max or min
void encoder_thresholds(i2cEncoderLibV2* obj) {
if ( obj->readStatus( RMAX))
if ( obj->readStatus( i2cEncoderLibV2::RMAX))
Serial.println("Max!");
else
Serial.println("Min!");
Expand Down Expand Up @@ -72,9 +72,9 @@ void setup(void)
Wire.begin();
Encoder.reset();

Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2:: WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!

Encoder.writeCounter((int32_t)0); /* Reset the counter value */
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
Expand Down
10 changes: 5 additions & 5 deletions examples/I2CEncoderV2/GPs_ADC/GPs_ADC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ void setup(void)

//Configure the Standard Encoder
STDEncoder.reset();
STDEncoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER);
STDEncoder.writeGP1conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.writeGP2conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.writeGP3conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER);
STDEncoder.writeGP1conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.writeGP2conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.writeGP3conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
STDEncoder.writeCounter((int32_t) 0);
STDEncoder.writeMax((int32_t) 10);
STDEncoder.writeMin((int32_t) 0);
STDEncoder.writeStep((int32_t) 1);
STDEncoder.writeInterruptConfig(INT2 | RINC | RDEC | RMAX | RMIN); //Enable all the interrupts
STDEncoder.writeInterruptConfig(i2cEncoderLibV2::INT_2 | i2cEncoderLibV2::RINC | i2cEncoderLibV2::RDEC | i2cEncoderLibV2::RMAX | i2cEncoderLibV2::RMIN); //Enable all the interrupts
STDEncoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
STDEncoder.updateStatus();

Expand Down
Loading

0 comments on commit 1862fc3

Please sign in to comment.