Compare commits

...

1 Commits

Author SHA1 Message Date
Leonardo Mendoza 6a65b51de7 primera funcion prototype 22 hours ago

@ -1,20 +1,21 @@
//Leonardo Mendoza 26-sep-2026
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
//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;
}

Loading…
Cancel
Save