You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.2 KiB

2 years ago
  1. //This project turns on, off or toggle an LED
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
  6. #define bled "/brightness"
  7. #define tled "/trigger"
  8. //Protypes:
  9. void writeLED(char fileName[], char value[]);
  10. void removeTrigger();
  11. //main:
  12. ////////////////////////////////////////////////////////
  13. int main(int argc, char* argv[]){
  14. printf("Starting app");
  15. if(argc!=2){
  16. printf("Incorrect number of arguments");
  17. return 2;
  18. }
  19. if(strcmp(argv[1], "on")==0){
  20. printf("LED on");
  21. removeTrigger();
  22. writeLED(bled, "1");
  23. printf("Done");
  24. }
  25. else if (strcmp(argv[1], "off")==0){
  26. printf("LED off");
  27. removeTrigger();
  28. writeLED(bled, "0");
  29. printf("Done");
  30. }
  31. else if (strcmp(argv[1], "blink")==0){
  32. printf("LED blinking");
  33. writeLED(tled, "timer");
  34. writeLED("/delay_on", "50");
  35. writeLED("/delay_off", "50");
  36. }
  37. else
  38. printf("Invalid command!\n");
  39. return 0;
  40. }
  41. ////////////////////////////////////////////////////////
  42. void writeLED(char fileName[], char value[]){
  43. FILE* fp;
  44. char fullName[150];
  45. sprintf(fullName, LED3_PATH "%s", fileName);
  46. fp = fopen(fullName, "w+");
  47. fprintf(fp, "%s", value);
  48. fclose(fp);
  49. }
  50. void removeTrigger(){
  51. writeLED(tled, "none");
  52. }