Skip to content

Instantly share code, notes, and snippets.

@ollewelin
Created September 14, 2016 04:35
Show Gist options
  • Save ollewelin/dff23bc942a4c64d191c203e9efa285f to your computer and use it in GitHub Desktop.
Save ollewelin/dff23bc942a4c64d191c203e9efa285f to your computer and use it in GitHub Desktop.
//File: gpio_test.c
#include "gpio_test.h"
int gpio_init(void)
{
if (!bcm2835_init())
return 1;
// Set the pin to be an output
bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN12, BCM2835_GPIO_FSEL_INPT);// Input pin
return 0;
}
void gpio_close(void)
{
bcm2835_close();
}
// Blinks on RPi Plug P1 pin 11 (which is GPIO pin 17)
void gpio_blink(void)
{
// Blink
// Turn it on
static uint32_t test_local = 0;//When static it will initialized one time and then count up
test_local++;
uint8_t read_lev;
bcm2835_gpio_write(PIN, HIGH);
printf("Pin 11 is now High test_local %d\n",test_local);
read_lev = bcm2835_gpio_lev(PIN12);
printf("Read GPIO pin level: %d\n",read_lev);
// wait a bit
bcm2835_delay(500);
// turn it off
bcm2835_gpio_write(PIN, LOW);
printf("Pin 11 is now Low \n");
read_lev = bcm2835_gpio_lev(PIN12);
printf("Read GPIO pin level: %d\n",read_lev);
// wait a bit
bcm2835_delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment