File: test_rotary_encoder.c

package info (click to toggle)
pigpio 1.78-1.1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 7,088 kB
  • sloc: ansic: 17,891; python: 4,232; sh: 741; cpp: 281; makefile: 135
file content (47 lines) | stat: -rw-r--r-- 599 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>

#include <pigpio.h>

#include "rotary_encoder.h"

/*

REQUIRES

A rotary encoder contacts A and B connected to separate gpios and
the common contact connected to Pi ground.

TO BUILD

gcc -o rot_enc_c test_rotary_encoder.c rotary_encoder.c -lpigpio -lrt

TO RUN

sudo ./rot_enc_c

*/

void callback(int way)
{
   static int pos = 0;

   pos += way;

   printf("pos=%d\n", pos);
}

int main(int argc, char *argv[])
{
   Pi_Renc_t * renc;

   if (gpioInitialise() < 0) return 1;

   renc = Pi_Renc(7, 8, callback);

   sleep(300);

   Pi_Renc_cancel(renc);

   gpioTerminate();
}