Advertisement
silver2row

"Bad to the Bone" older source...

Jun 1st, 2020
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <time.h>
  4.  
  5. #define OUTPUT ”out”
  6. #define INPUT ”in”
  7.  
  8. int main (void) { // define file handles
  9.   FILE * ofp_export , * ofp_gpio44_value , * ofp_gpio44_direction ;
  10.  
  11. // define pin variables
  12. int pin_number = 44, logic_status = 1; char * pin_direction = OUTPUT;
  13.  
  14. // define pin variables
  15. int pin_number = 44, logic_status = 1;
  16. char* pin_direction = OUTPUT;
  17.  
  18. // establish a direction and value file within export for gpio44
  19.   ofp_export = fopen("/sys/class/gpio/export", "w");
  20.   if(ofp_export == NULL) {printf("Unable to open export.\n");}
  21.     fseek(ofp_export, 0, SEEK_SET);
  22.     fprintf(ofp_export, "%d", pin_number);
  23.     fflush(ofp_export);
  24.  
  25. // configure gpio44 for writing
  26.   ofp_gpio44_direction = fopen("/sys/class/gpio/gpio44/direction", "w");
  27.   if(ofp_gpio44_direction == NULL){printf("Unable to open gpio44_direction.\n");}
  28.     fseek(ofp_gpio44_direction, 0, SEEK_SET);
  29.     fprintf(ofp_gpio44_direction, "%s", pin_direction);
  30.     fflush(ofp_gpio44_direction);
  31.  
  32. // write a logic 1 to gpio44 to illuminate the LED
  33.   ofp_gpio44_value = fopen("/sys/class/gpio/gpio44/value", "w");
  34.   if(ofp_gpio44_value == NULL) {printf("Unable to open gpio44_value.\n");}
  35.     fseek(ofp_gpio44_value, 0, SEEK_SET);
  36.     fprintf(ofp_gpio44_value, "%d", logic_status);
  37.     fflush(ofp_gpio44_value);
  38.  
  39. // close the files
  40.   fclose(ofp_export);
  41.   fclose(ofp_gpio44_direction);
  42.   fclose(ofp_gpio44_value);
  43.  
  44.   return 1;
  45. }
  46.  
  47. From a book, "Bad to the Bone."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement