test_rotary_encoder.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <pigpio.h>
4 
5 #include "rotary_encoder.hpp"
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 g++ -o rot_enc_cpp test_rotary_encoder.cpp rotary_encoder.cpp -lpigpio -lrt
17 
18 TO RUN
19 
20 sudo ./rot_enc_cpp
21 
22 */
23 
24 void callback(int way)
25 {
26  static int pos = 0;
27 
28  pos += way;
29 
30  std::cout << "pos=" << pos << std::endl;
31 }
32 
33 int main(int argc, char *argv[])
34 {
35  if (gpioInitialise() < 0) return 1;
36 
37  re_decoder dec(7, 8, callback);
38 
39  sleep(3000);
40 
41  dec.re_cancel();
42 
43  gpioTerminate();
44 }
45 
int gpioInitialise(void)
Definition: pigpio.c:8459
void callback(int way)
void re_cancel(void)
void gpioTerminate(void)
Definition: pigpio.c:8495
int main(int argc, char *argv[])


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