test_rotary_encoder.c
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include <pigpio.h>
4 
5 #include "rotary_encoder.h"
6 
7 /*
8 
9 REQUIRES
10 
11 A rotary encoder contacts A and B connected to separate gpios and
12 the common contact connected to Pi ground.
13 
14 TO BUILD
15 
16 gcc -o rot_enc_c test_rotary_encoder.c rotary_encoder.c -lpigpio -lrt
17 
18 TO RUN
19 
20 sudo ./rot_enc_c
21 
22 */
23 
24 void callback(int way)
25 {
26  static int pos = 0;
27 
28  pos += way;
29 
30  printf("pos=%d\n", pos);
31 }
32 
33 int main(int argc, char *argv[])
34 {
35  Pi_Renc_t * renc;
36 
37  if (gpioInitialise() < 0) return 1;
38 
39  renc = Pi_Renc(7, 8, callback);
40 
41  sleep(300);
42 
43  Pi_Renc_cancel(renc);
44 
45  gpioTerminate();
46 }
47 
int gpioInitialise(void)
Definition: pigpio.c:8459
int main(int argc, char *argv[])
void Pi_Renc_cancel(Pi_Renc_t *renc)
Pi_Renc_t * Pi_Renc(int gpioA, int gpioB, Pi_Renc_CB_t callback)
void gpioTerminate(void)
Definition: pigpio.c:8495
void callback(int way)


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57