pikeyd165 – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 // input.c
2 //
3 // Example program for bcm2835 library
4 // Reads and prints the state of an input pin
5 //
6 // After installing bcm2835, you can build this
7 // with something like:
8 // gcc -o input input.c -l bcm2835
9 // sudo ./input
10 //
11 // Or you can test it before installing with:
12 // gcc -o input -I ../../src ../../src/bcm2835.c input.c
13 // sudo ./input
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  
39 // Blink
40 while (1)
41 {
42 // Read some data
43 uint8_t value = bcm2835_gpio_lev(PIN);
44 printf("read from pin 15: %d\n", value);
45  
46 // wait a bit
47 delay(500);
48 }
49  
50 bcm2835_close();
51 return 0;
52 }
53