A C example to make work the LED on BeagleBone-Black and Pocket.
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.

53 lines
1.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // LED application in C by
  2. // Gerado Marx Chavez Campos, 26/04/2021
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. #define LED3PATH "/sys/class/leds/beaglebone:green:usr3"
  7. #define bon "/brightness"
  8. #define trg "/trigger"
  9. //Function prototypes
  10. void WriteLED(char fileName[], char value[]);
  11. void RemoveTrigger();
  12. //main
  13. int main(int argc, char* argv[]){
  14. if(argc!=2){
  15. printf("Incorrect use of command...\n");
  16. printf("Please use LEDc with:\n");
  17. printf("on, off, flash or status.\n");
  18. printf("\n");
  19. printf("Example: LEDc on\n");
  20. return 2;
  21. }
  22. printf("Starting Application...\n");
  23. //checking the command argument:
  24. if(strcmp(argv[1], "on")==0){
  25. printf("Turning LED on\n");
  26. RemoveTrigger();
  27. WriteLED(bon,"1");
  28. }
  29. else if(strcmp(argv[1], "off")==0){
  30. printf("Turning LED off\n");
  31. RemoveTrigger();
  32. WriteLED(bon,"0");
  33. }
  34. printf("LED Application Done\n");
  35. return 0;
  36. }
  37. //complete functions here:
  38. void WriteLED(char filename[], char value[]){
  39. FILE* fp; //file pointer
  40. char fileName[100]; //var to store path and file
  41. sprintf(fileName, LED3PATH "%s", filename);
  42. fp = fopen(fileName, "w+");
  43. fprintf(fp, "%s", value);
  44. fclose(fp);
  45. }
  46. void RemoveTrigger(){
  47. WriteLED(trg, "none");
  48. }