Browse Source

First commit

master
Gustavo Martinez 2 years ago
commit
cdd2b838d5
2 changed files with 66 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +65
    -0
      main.c

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
led

+ 65
- 0
main.c View File

@ -0,0 +1,65 @@
//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");
if(argc!=2){
printf("Incorrect number of arguments");
return 2;
}
if(strcmp(argv[1], "on")==0){
printf("LED on");
removeTrigger();
writeLED(bled, "1");
printf("Done");
}
else if (strcmp(argv[1], "off")==0){
printf("LED off");
removeTrigger();
writeLED(bled, "0");
printf("Done");
}
else if (strcmp(argv[1], "blink")==0){
printf("LED blinking");
writeLED(tled, "timer");
writeLED("/delay_on", "50");
writeLED("/delay_off", "50");
}
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");
}

Loading…
Cancel
Save