All pastes #606906 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-07 05:57 UTC
rendered paste body
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/gpio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int main(void) {
    struct gpio_pin_op op[8];
    int devfd;
    int i;

    op[0].gp_pin = 5;
    op[1].gp_pin = 6;
    op[2].gp_pin = 7;
    op[3].gp_pin = 8;
    op[4].gp_pin = 21;
    op[5].gp_pin = 22;
    op[6].gp_pin = 11;
    op[7].gp_pin = 12;

    devfd = open("/dev/gpio0", O_RDWR);

    pid_t pid = fork();

    // Child
    if (pid == 0) {
      while(1) {
        //printf("activating leds...\n");
        for(i=2; i<8; i++) {
          op[i].gp_value = GPIO_PIN_LOW;
	  ioctl(devfd, GPIOPINWRITE, &op[i]);
	  usleep(100000);
	}
	//printf("now turning all leds off...\n");
	for(i=2; i<8; i++) {
	  op[i].gp_value = GPIO_PIN_HIGH;
          ioctl(devfd, GPIOPINWRITE, &op[i]);
	  usleep(100000);
	}
      }
    }
    // Parent
    else {
      while (1) {
	op[0].gp_value = GPIO_PIN_LOW;
	ioctl(devfd, GPIOPINWRITE, &op[0]);
	usleep(50000);
	op[0].gp_value = GPIO_PIN_HIGH;
	ioctl(devfd, GPIOPINWRITE, &op[0]);
	usleep(50000);
      }
    }
}