bcm2835 1.75
input.c

Reads the state of an RPi input pin

// input.c
//
// Example program for bcm2835 library
// Reads and prints the state of an input pin
//
// After installing bcm2835, you can build this
// with something like:
// gcc -o input input.c -l bcm2835
// sudo ./input
//
// Or you can test it before installing with:
// gcc -o input -I ../../src ../../src/bcm2835.c input.c
// sudo ./input
//
// 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 15
#define PIN RPI_GPIO_P1_15
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-15 to be an input
// with a pullup
// Blink
while (1)
{
// Read some data
uint8_t value = bcm2835_gpio_lev(PIN);
printf("read from pin 15: %d\n", value);
// wait a bit
delay(500);
}
return 0;
}
@ BCM2835_GPIO_PUD_UP
Definition: bcm2835.h:906
@ BCM2835_GPIO_FSEL_INPT
Definition: bcm2835.h:888
uint8_t bcm2835_gpio_lev(uint8_t pin)
Definition: bcm2835.c:343
void bcm2835_gpio_set_pud(uint8_t pin, uint8_t pud)
Definition: bcm2835.c:635
void bcm2835_gpio_fsel(uint8_t pin, uint8_t mode)
Definition: bcm2835.c:302
int bcm2835_close(void)
Definition: bcm2835.c:2163
int bcm2835_init(void)
Definition: bcm2835.c:2008