hall.c
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include <pigpio.h>
4 
5 /*
6 OH3144E or equivalent Hall effect sensor
7 
8 Pin 1 - 5V
9 Pin 2 - Ground
10 Pin 3 - gpio (here P1-8, gpio 14, TXD is used)
11 
12 The internal gpio pull-up is enabled so that the sensor
13 normally reads high. It reads low when a magnet is close.
14 
15 gcc -o hall hall.c -lpigpio -lrt -lpthread
16 sudo ./hall
17 */
18 
19 #define HALL 14
20 
21 void alert(int gpio, int level, uint32_t tick)
22 {
23  static uint32_t lastTick=0;
24 
25  if (lastTick) printf("%d %.2f\n", level, (float)(tick-lastTick)/1000000.0);
26  else printf("%d 0.00\n", level);
27 
28  lastTick = tick;
29 }
30 
31 int main(int argc, char *argv[])
32 {
33  int secs=60;
34 
35  if (argc>1) secs = atoi(argv[1]); /* program run seconds */
36 
37  if ((secs<1) || (secs>3600)) secs = 3600;
38 
39  if (gpioInitialise()<0) return 1;
40 
42 
44 
46 
47  sleep(secs);
48 
49  gpioTerminate();
50 }
51 
#define HALL
Definition: hall.c:19
int gpioInitialise(void)
Definition: pigpio.c:8459
int gpioSetAlertFunc(unsigned gpio, gpioAlertFunc_t f)
Definition: pigpio.c:11303
void alert(int gpio, int level, uint32_t tick)
Definition: hall.c:21
int gpioSetMode(unsigned gpio, unsigned mode)
Definition: pigpio.c:8607
#define PI_PUD_UP
Definition: pigpio.h:594
int main(int argc, char *argv[])
Definition: hall.c:31
#define PI_INPUT
Definition: pigpio.h:581
void gpioTerminate(void)
Definition: pigpio.c:8495
int gpioSetPullUpDown(unsigned gpio, unsigned pud)
Definition: pigpio.c:8661


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