Last active
August 29, 2015 14:16
-
-
Save krishnan793/b8b071e02ca83b24995a to your computer and use it in GitHub Desktop.
This program will blink an LED connected to gpio23 of BeagleBoneBlack Board. Inorder for the code to work first set gpio port 23 as output. (echo 23 > /sys/class/gpio/export && echo out > /sys/class/gpio/gpio23/direction))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include <unistd.h> | |
int main(int argc, char* argv[]) | |
{ | |
if(argc!=3){ | |
printf("Syntax: %s <no_of_times_to_blink> <delay_us>\n",argv[0]); | |
return 0; | |
} | |
int delay=atoi(argv[2]); | |
int no=atoi(argv[1]); | |
FILE *LEDHandler=NULL; | |
char *LEDPath="/sys/class/gpio/gpio23/value"; | |
int i; | |
for(i=0;i<no;i++){ | |
if(LEDHandler=fopen(LEDPath,"r+")){ | |
printf("LED on\n\033[F\033[J"); | |
fwrite("1", 1, 1,LEDHandler); | |
fclose(LEDHandler); | |
} | |
usleep(delay); | |
if(LEDHandler=fopen(LEDPath,"r+")){ | |
printf("LED off\n\033[F\033[J"); | |
fwrite("0", 1, 1,LEDHandler); | |
fclose(LEDHandler); | |
} | |
usleep(delay); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment