Go to the documentation of this file.00001 #include <stdio.h>
00002
00003 #include <pigpio.h>
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define HALL 14
00020
00021 void alert(int gpio, int level, uint32_t tick)
00022 {
00023 static uint32_t lastTick=0;
00024
00025 if (lastTick) printf("%d %.2f\n", level, (float)(tick-lastTick)/1000000.0);
00026 else printf("%d 0.00\n", level);
00027
00028 lastTick = tick;
00029 }
00030
00031 int main(int argc, char *argv[])
00032 {
00033 int secs=60;
00034
00035 if (argc>1) secs = atoi(argv[1]);
00036
00037 if ((secs<1) || (secs>3600)) secs = 3600;
00038
00039 if (gpioInitialise()<0) return 1;
00040
00041 gpioSetMode(HALL, PI_INPUT);
00042
00043 gpioSetPullUpDown(HALL, PI_PUD_UP);
00044
00045 gpioSetAlertFunc(HALL, alert);
00046
00047 sleep(secs);
00048
00049 gpioTerminate();
00050 }
00051