Created
January 2, 2017 13:51
-
-
Save aycabta/d9070997dba4e665371a34ba0d1b1c88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/cdefs.h> | |
__FBSDID("$FreeBSD$"); | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <sys/gpio.h> | |
int gpio_write(int fd, int pin, int value) | |
{ | |
int ret; | |
struct gpio_req req; | |
req.gp_pin = pin; | |
req.gp_value = value; | |
ret = ioctl(fd, GPIOSET, &req); | |
if (ret < 0) { | |
perror("ioctl(GPIOSET)"); | |
exit(2); | |
} | |
return ret; | |
} | |
int main(void) | |
{ | |
int fd; | |
fd = open("/dev/gpioc0", O_RDONLY); | |
if (fd < 0) { | |
perror("open"); | |
exit(1); | |
} | |
gpio_write(fd, 18, 1); | |
sleep(1); | |
gpio_write(fd, 18, 0); | |
sleep(1); | |
gpio_write(fd, 18, 1); | |
sleep(1); | |
gpio_write(fd, 18, 0); | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment