test_rotary_encoder.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <pigpio.h>
00004 
00005 #include "rotary_encoder.hpp"
00006 
00007 /*
00008 
00009 REQUIRES
00010 
00011 A rotary encoder contacts A and B connected to separate gpios and
00012 the common contact connected to Pi ground.
00013 
00014 TO BUILD
00015 
00016 g++ -o rot_enc_cpp test_rotary_encoder.cpp rotary_encoder.cpp -lpigpio -lrt
00017 
00018 TO RUN
00019 
00020 sudo ./rot_enc_cpp
00021 
00022 */
00023 
00024 void callback(int way)
00025 {
00026    static int pos = 0;
00027 
00028    pos += way;
00029 
00030    std::cout << "pos=" << pos << std::endl;
00031 }
00032 
00033 int main(int argc, char *argv[])
00034 {
00035    if (gpioInitialise() < 0) return 1;
00036 
00037    re_decoder dec(7, 8, callback);
00038 
00039    sleep(3000);
00040 
00041    dec.re_cancel();
00042 
00043    gpioTerminate();
00044 }
00045 


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Thu Jun 6 2019 20:43:57