Este es un repositorio para controlar un LED de la Beagle Bone Black
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.

63 lines
1.5 KiB

2 years ago
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. #include<time.h>
  6. #define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
  7. #define bled "/brightness"
  8. #define tled "/trigger"
  9. #define en "/delay_on"
  10. #define ap "/delay_off"
  11. //Protypes:
  12. void writeLED(char fileName[], char value[]);
  13. void removeTrigger();
  14. //main:
  15. ////////////////////////////////////////////////////////
  16. int main(int argc, char* argv[]){
  17. printf("Starting app\n");
  18. //writeLED(bled, "1");
  19. //printf("Done");
  20. //return 0;
  21. //strcmp(argv[1], "on")==0;
  22. //
  23. if(strcmp(argv[1],"on")==0){
  24. printf("encendiendo LED\n");
  25. removeTrigger();
  26. writeLED(bled,"1");
  27. }
  28. else if(strcmp(argv[1], "off")==0){
  29. printf("apagando LED\n");
  30. removeTrigger();
  31. writeLED(bled,"0");
  32. }
  33. else if(strcmp(argv[1],"blink")==0){
  34. printf("blink\n");
  35. writeLED(tled,"timer");
  36. writeLED("en","50");
  37. writeLED("ap","50");
  38. }
  39. else{
  40. printf("comando invalido");
  41. printf("Para encender el LED utilice: ./Nombre_del_archivo2 on \n");
  42. printf("Para apagar el LED utilice: ./Nombre_del_archivo2 off \n");
  43. printf("Para hacer parpadear el LED utilice: sudo ./Nombre_del_archivo2 blink \n ");
  44. }
  45. printf("programa finalizado");
  46. return 0;
  47. }
  48. ////////////////////////////////////////////////////////
  49. void writeLED(char fileName[], char value[]){
  50. FILE* fp;
  51. char fullName[150];
  52. sprintf(fullName, LED3_PATH "%s", fileName);
  53. fp = fopen(fullName, "w+");
  54. fprintf(fp, "%s", value);
  55. fclose(fp);
  56. }
  57. void removeTrigger(){
  58. writeLED(tled, "none");
  59. }