Browse Source

On and Off ok

master
parent
commit
4e1089258c
1 changed files with 35 additions and 9 deletions
  1. +35
    -9
      main.c

+ 35
- 9
main.c View File

@ -1,27 +1,53 @@
// LED application in C by
// Gerado Marx Chavez Campos
// 26/04/2021
//
//
// 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* argvp[]){
int main(int argc, char* argv[]){
if(argc!=2){
printf("Incorrect use...");
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("LED Application Done");
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");
}

Loading…
Cancel
Save