|
|
- // LED application in C by
- // Gerado Marx Chavez Campos, 26/04/2021
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
-
- #define LED3PATH "/sys/class/leds/beaglebone:green:usr3"
- #define bon "/brightness"
- #define trg "/trigger"
-
- //Function prototypes
- void WriteLED(char fileName[], char value[]);
- void RemoveTrigger();
-
- //main
- int main(int argc, char* argv[]){
- if(argc!=2){
- printf("Incorrect use of command...\n");
- printf("Please use LEDc with:\n");
- printf("on, off, flash or status.\n");
- printf("\n");
- printf("Example: LEDc on\n");
- return 2;
- }
- printf("Starting Application...\n");
- //checking the command argument:
- if(strcmp(argv[1], "on")==0){
- printf("Turning LED on\n");
- RemoveTrigger();
- WriteLED(bon,"1");
- }
- else if(strcmp(argv[1], "off")==0){
- printf("Turning LED off\n");
- RemoveTrigger();
- WriteLED(bon,"0");
- }
- printf("LED Application Done\n");
- return 0;
- }
-
- //complete functions here:
- void WriteLED(char filename[], char value[]){
- FILE* fp; //file pointer
- char fileName[100]; //var to store path and file
- sprintf(fileName, LED3PATH "%s", filename);
- fp = fopen(fileName, "w+");
- fprintf(fp, "%s", value);
- fclose(fp);
- }
- void RemoveTrigger(){
- WriteLED(trg, "none");
- }
-
|