|
|
- //This project turns on, off or toggle an LED
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<time.h>
- #define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
- #define bled "/brightness"
- #define tled "/trigger"
- #define en "/delay_on"
- #define ap "/delay_off"
- //Protypes:
- void writeLED(char fileName[], char value[]);
- void removeTrigger();
- //main:
- ////////////////////////////////////////////////////////
- int main(int argc, char* argv[]){
- printf("Starting app\n");
- //writeLED(bled, "1");
- //printf("Done");
- //return 0;
- //strcmp(argv[1], "on")==0;
- //
- if(strcmp(argv[1],"on")==0){
- printf("encendiendo LED\n");
- removeTrigger();
- writeLED(bled,"1");
- }
- else if(strcmp(argv[1], "off")==0){
- printf("apagando LED\n");
- removeTrigger();
- writeLED(bled,"0");
- }
- else if(strcmp(argv[1],"blink")==0){
- printf("blink\n");
- writeLED(tled,"timer");
- writeLED("en","50");
- writeLED("ap","50");
- }
-
- else{
- printf("comando invalido");
- }
- printf("programa finalizado");
- return 0;
- }
-
- ////////////////////////////////////////////////////////
- void writeLED(char fileName[], char value[]){
- FILE* fp;
- char fullName[150];
- sprintf(fullName, LED3_PATH "%s", fileName);
- fp = fopen(fullName, "w+");
- fprintf(fp, "%s", value);
- fclose(fp);
- }
-
- void removeTrigger(){
- writeLED(tled, "none");
- }
-
|