Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple gpiod example of toggling a LED connected a gpio line from
- the BeagleBone Black Wireless and RelayCape.
- Exits when CTRL-C is typed. Seth typed this driver with help
- from ICS.com and their GPIO series...
- */
- #include <gpiod.h>
- #include <stdio.h>
- #include <unistd.h>
- int main(int argc, char **argv)
- {
- const char *chipname = "gpiochip3";
- struct gpiod_chip *chip;
- struct gpiod_line *lineRed; // Red LED
- int i, ret, val;
- // Open GPIO chip
- chip = gpiod_chip_open_by_name(chipname);
- if (!chip) {
- perror("Open chip failed\n");
- return 1;
- }
- // Open GPIO lines
- lineRed = gpiod_chip_get_line(chip, 16);
- if (!lineRed) {
- perror("Get line failed\n");
- return 1;
- }
- // Open LED line for output
- ret = gpiod_line_request_output(lineRed, "MySecond", 0);
- if (ret < 0) {
- perror("Request line as output failed\n");
- return 1;
- }
- // Blink a LED
- i = 0;
- while (true) {
- ret = gpiod_line_set_value(lineRed, (i & 1) != 0);
- if (ret < 0) {
- perror("Set line output failed\n");
- return 1;
- }
- usleep(1000000);
- i++;
- }
- // Release lines and chip
- gpiod_line_release(lineRed);
- gpiod_chip_close(chip);
- return 0;
- }
Add Comment
Please, Sign In to add comment