// blinkgpio.cpp // Author: Jim Merkle // Date: 1/25/2017 // Toggle a GPIO pin #include #include #include #define GPIO_PIN 4 void msleep(int milliseconds) { usleep(milliseconds * 1000); } int main(int argc, char * argv[]) { printf("LED is now Blinking on GPIO %d\n",GPIO_PIN); char command[100]; char command_on[100]; char command_off[100]; sprintf(command,"echo %d > /sys/class/gpio/export",GPIO_PIN); system(command); msleep(500); // allow time for the system to create directory tree sprintf(command,"echo \"out\" > /sys/class/gpio/gpio%d/direction",GPIO_PIN); system(command); sprintf(command_on,"echo 1 > /sys/class/gpio/gpio%d/value",GPIO_PIN); sprintf(command_off,"echo 0 > /sys/class/gpio/gpio%d/value",GPIO_PIN); for(int i=0;i<10;i++) { system(command_on); msleep(200); system(command_off); msleep(200); } sprintf(command,"echo %d > /sys/class/gpio/unexport",GPIO_PIN); system(command); return 0; }