From cb62f445e4ac3f08eae8922a9da5e2cc843840e3 Mon Sep 17 00:00:00 2001 From: Ignacio Abundez Date: Thu, 24 Sep 2026 10:55:33 -0600 Subject: [PATCH] added the gpio_direction function --- main.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index f09b1d1..7660808 100644 --- a/main.c +++ b/main.c @@ -15,17 +15,10 @@ int gpio_write(int gpio, int value); int main (int argc, char *argv[]){ int fd; - char pin[] = "17"; - + char pin[] = "17"; gpio_export(pin); + char direction[] = "out"; //pin direction - fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY); - if (fd < 0){ - perror("Error opening the GPIO path"); - return -1; - } - write(fd,"out", 3); - close(fd); //pin value @@ -79,7 +72,25 @@ int gpio_export(const char *gpio){ perror("Error opening the GPIO path"); return -1; } - write(fd,gpio, strlen(gpio)); + write(fd, gpio, strlen(gpio)); close(fd); return(0); } +//pin_directions + +int gpio_direction(int gpio, const char *direction){ + + int fd; + + fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY); + if (fd < 0){ + perror("Error opening the GPIO path"); + return -1; + } + write(fd, direction, 3); + close(fd); + return (0); +} +//pin_value + +