diff --git a/main.c b/main.c index bc276c3..b125c30 100644 --- a/main.c +++ b/main.c @@ -1,20 +1,21 @@ +//Leonardo Mendoza 26-sep-2026 #include #include #include +#include + +//Prototypes +int gpio_export(const char *gpio); +int gpio_direction(int gpio, const char *direction); +int gpio_write(int gpio, int value); + int main(int argc, char *argv[]) { - int fd; - // EXPORT - fd = open("/sys/class/gpio/chip0/export", O_WRONLY); - if(fd<0) - { - perror("Error opening GPIO export path"); - return -1; - } + char pin[] = "17"; + gpio_export(pin); - write(fd, "17", 2); - close(fd); + int fd; // DIRECTION fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY); if(fd<0) @@ -76,3 +77,20 @@ int main(int argc, char *argv[]) return 0; } + +//Full functions +int gpio_export(const char *gpio) +{ + int fd; + // EXPORT + fd = open("/sys/class/gpio/chip0/export", O_WRONLY); + if(fd<0) + { + perror("Error opening GPIO export path"); + return -1; + } + write(fd, gpio, strlen(gpio)); + close(fd); + return 0; +} +