test_rotary_encoder.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include <pigpio.h>
00004 
00005 #include "rotary_encoder.h"
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 gcc -o rot_enc_c test_rotary_encoder.c rotary_encoder.c -lpigpio -lrt
00017 
00018 TO RUN
00019 
00020 sudo ./rot_enc_c
00021 
00022 */
00023 
00024 void callback(int way)
00025 {
00026    static int pos = 0;
00027 
00028    pos += way;
00029 
00030    printf("pos=%d\n", pos);
00031 }
00032 
00033 int main(int argc, char *argv[])
00034 {
00035    Pi_Renc_t * renc;
00036 
00037    if (gpioInitialise() < 0) return 1;
00038 
00039    renc = Pi_Renc(7, 8, callback);
00040 
00041    sleep(300);
00042 
00043    Pi_Renc_cancel(renc);
00044 
00045    gpioTerminate();
00046 }
00047 


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