Skip to content

Instantly share code, notes, and snippets.

@hsiboy hsiboy/button.c
Created Mar 6, 2014

What would you like to do?
Raspberry Pi - detect button press
// button.c
// gcc -o button button.c -l bcm2835
// run as root
// sudo ./button
#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 (!bcm2835_init())
return 1;
// Set PIN to be an input
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
// add a pullup
bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP);
// and enble low
while (1)
if (bcm2835_gpio_eds(PIN))
// Now clear the eds flag by setting it to 1
printf("Button Pressed!\n");
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.