|
|
- //This project turns on, off or toggle an LED
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
-
- #define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
- #define bled "/brightness"
- #define tled "/trigger"
-
- //Protypes:
- void writeLED(char fileName[], char value[]);
- void removeTrigger();
-
- //main:
- ////////////////////////////////////////////////////////
- int main(int argc, char* argv[]){
- printf("Starting app \n");
-
- if(argc!=2){
- printf("Incorrect number of arguments");
- return 2;
- }
-
- if(strcmp(argv[1], "on")==0){
- printf("LED on \n");
- removeTrigger();
- writeLED(bled, "1");
- printf("Done");
- }
-
- else if (strcmp(argv[1], "off")==0){
- printf("LED off \n");
- removeTrigger();
- writeLED(bled, "0");
- printf("Done");
- }
-
- else if (strcmp(argv[1], "blink")==0){
- printf("LED blinking \n");
- writeLED(tled, "timer");
- writeLED("/delay_on", "500");
- writeLED("/delay_off", "500");
- }
-
- else
- printf("Invalid command!\n");
-
- 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");
- }
-
|