pikeyd165 – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | // event.c |
2 | // |
||
3 | // Example program for bcm2835 library |
||
4 | // Event detection of an input pin |
||
5 | // |
||
6 | // After installing bcm2835, you can build this |
||
7 | // with something like: |
||
8 | // gcc -o event event.c -l bcm2835 |
||
9 | // sudo ./event |
||
10 | // |
||
11 | // Or you can test it before installing with: |
||
12 | // gcc -o event -I ../../src ../../src/bcm2835.c event.c |
||
13 | // sudo ./event |
||
14 | // |
||
15 | // Author: Mike McCauley |
||
16 | // Copyright (C) 2011 Mike McCauley |
||
17 | // $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $ |
||
18 | |||
19 | #include <bcm2835.h> |
||
20 | #include <stdio.h> |
||
21 | |||
22 | // Input on RPi pin GPIO 15 |
||
23 | #define PIN RPI_GPIO_P1_15 |
||
24 | |||
25 | int main(int argc, char **argv) |
||
26 | { |
||
27 | // If you call this, it will not actually access the GPIO |
||
28 | // Use for testing |
||
29 | // bcm2835_set_debug(1); |
||
30 | |||
31 | if (!bcm2835_init()) |
||
32 | return 1; |
||
33 | |||
34 | // Set RPI pin P1-15 to be an input |
||
35 | bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT); |
||
36 | // with a pullup |
||
37 | bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP); |
||
38 | // And a low detect enable |
||
39 | bcm2835_gpio_len(PIN); |
||
40 | |||
41 | while (1) |
||
42 | { |
||
43 | if (bcm2835_gpio_eds(PIN)) |
||
44 | { |
||
45 | // Now clear the eds flag by setting it to 1 |
||
46 | bcm2835_gpio_set_eds(PIN); |
||
47 | printf("low event detect for pin 15\n"); |
||
48 | } |
||
49 | |||
50 | // wait a bit |
||
51 | delay(500); |
||
52 | } |
||
53 | |||
54 | bcm2835_close(); |
||
55 | return 0; |
||
56 | } |
||
57 |