1616
1717const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board */
1818// Class initialization with the I2C addresses
19- i2cEncoderLibV2 Encoder (0x61 ); /* A0 is soldered */
20-
19+ i2cEncoderLibV2 Encoder (0x01 ); /* A0 is soldered */
2120
2221// Callback when the CVAL is incremented
2322void encoder_increment (i2cEncoderLibV2* obj) {
2423 Serial.print (" Increment: " );
25- Serial.println ( Encoder.readCounterByte ());
24+ Serial.println (Encoder.readCounterByte ());
2625}
2726
28-
29-
3027// Callback when the CVAL is decremented
3128void encoder_decrement (i2cEncoderLibV2* obj) {
3229 Serial.print (" Decrement: " );
33- Serial.println ( Encoder.readCounterByte ());
30+ Serial.println (Encoder.readCounterByte ());
3431}
3532
36-
37-
3833// Callback when CVAL reach MAX
3934void encoder_max (i2cEncoderLibV2* obj) {
4035 Serial.print (" Maximum threshold: " );
41- Serial.println ( Encoder.readCounterByte ());
36+ Serial.println (Encoder.readCounterByte ());
4237}
4338
44-
45-
46-
4739// Callback when CVAL reach MIN
4840void encoder_min (i2cEncoderLibV2* obj) {
4941 Serial.print (" Minimum threshold: " );
50- Serial.println ( Encoder.readCounterByte ());
42+ Serial.println (Encoder.readCounterByte ());
5143}
5244
53-
54-
55-
5645// Callback when the encoder is pushed
5746void encoder_push (i2cEncoderLibV2* obj) {
5847 Serial.println (" Encoder is pushed!" );
5948}
6049
61-
62-
6350// Callback when the encoder is released
6451void encoder_released (i2cEncoderLibV2* obj) {
6552 Serial.println (" Encoder is released" );
6653}
6754
68-
69-
7055// Callback when the encoder is double pushed
7156void encoder_double_push (i2cEncoderLibV2* obj) {
7257 Serial.println (" Encoder is double pushed!" );
7358}
7459
75-
76-
77-
78- void setup (void )
79- {
60+ void setup (void ) {
8061 pinMode (IntPin, INPUT);
8162 Wire.begin ();
8263 Serial.begin (115200 );
8364 Serial.println (" **** I2C Encoder V2 basic example ****" );
8465 /*
85- INT_DATA= The register are considered integer.
86- WRAP_DISABLE= The WRAP option is disabled
87- DIRE_LEFT= Encoder left direction increase the value
88- IPUP_ENABLE= INT pin have the pull-up enabled.
89- RMOD_X1= Encoder configured as X1.
90- RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
66+ INT_DATA= The register are considered integer.
67+ WRAP_DISABLE= The WRAP option is disabled
68+ DIRE_LEFT= Encoder left direction increase the value
69+ IPUP_ENABLE= INT pin have the pull-up enabled.
70+ RMOD_X1= Encoder configured as X1.
71+ RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
9172 */
9273 Encoder.reset ();
93- Encoder.begin (INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
94- // Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
95- // Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
96-
97- Encoder.writeCounter ((int32_t )0 ); /* Reset the counter value */
98- Encoder.writeMax ((int32_t )10 ); /* Set the maximum threshold*/
74+ Encoder.begin (
75+ i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE
76+ | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE
77+ | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
78+ // Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
79+ // Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
80+
81+ Encoder.writeCounter ((int32_t ) 0 ); /* Reset the counter value */
82+ Encoder.writeMax ((int32_t ) 10 ); /* Set the maximum threshold*/
9983 Encoder.writeMin ((int32_t ) - 10 ); /* Set the minimum threshold */
100- Encoder.writeStep ((int32_t )1 ); /* Set the step to 1*/
101- Encoder.writeAntibouncingPeriod (20 ); /* Set an anti-bouncing of 200ms */
102- Encoder.writeDoublePushPeriod (50 ); /* Set a period for the double push of 500ms */
103-
84+ Encoder.writeStep ((int32_t ) 1 ); /* Set the step to 1*/
85+ Encoder.writeAntibouncingPeriod (20 ); /* Set an anti-bouncing of 200ms */
86+ Encoder.writeDoublePushPeriod (50 ); /* Set a period for the double push of 500ms */
87+
10488 // Definition of the events
10589 Encoder.onIncrement = encoder_increment;
10690 Encoder.onDecrement = encoder_decrement;
@@ -109,9 +93,9 @@ void setup(void)
10993 Encoder.onButtonPush = encoder_push;
11094 Encoder.onButtonRelease = encoder_released;
11195 Encoder.onButtonDoublePush = encoder_double_push;
112-
96+
11397 /* Enable the I2C Encoder V2 interrupts according to the previus attached callback */
114- Encoder.autoconfigInterrupt ();
98+ Encoder.autoconfigInterrupt ();
11599
116100}
117101
@@ -120,4 +104,4 @@ void loop() {
120104 /* Check the status of the encoder and call the callback */
121105 Encoder.updateStatus ();
122106 }
123- }
107+ }
0 commit comments