-
Notifications
You must be signed in to change notification settings - Fork 0
/
e.c
48 lines (48 loc) · 1.23 KB
/
e.c
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
48
// e.c
//
// Example program for bcm2835 library
// Event detection of an input pin
//
// After installing bcm2835, you can build this
// with something like:
// gcc -o e e.c -l bcm2835 -l rt
// sudo ./e
//
// Or you can test it before installing with:
// gcc -o event -I ../../src ../../src/bcm2835.c event.c
// sudo ./event
//
// Author: Mike McCauley
// Copyright (C) 2011 Mike McCauley
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $
#include <bcm2835.h>
#include <stdio.h>
// Input on RPi pin GPIO 13
#define PIN RPI_GPIO_P1_13
int main(int argc, char **argv)
{
// If you call this, it will not actually access the GPIO
// Use for testing
// bcm2835_set_debug(1);
if (!bcm2835_init())
return 1;
// Set RPI pin P1-13 to be an input
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
// with a pullup
bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP);
// And a low detect enable
bcm2835_gpio_len(PIN);
while (1)
{
if (bcm2835_gpio_eds(PIN))
{
// Now clear the eds flag by setting it to 1
bcm2835_gpio_set_eds(PIN);
printf("low event detect for pin 13\n");
}
// wait a bit
delay(500);
}
bcm2835_close();
return 0;
}