Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1.     #include <string.h>
  2.     #include <stdio.h>
  3.     #include <stdlib.h>
  4.     #include <unistd.h>
  5.     #include <errno.h>
  6.  
  7.     void sysfs_write (const char *path, const char *value)
  8.         {
  9.             path=value;
  10.         }
  11.  
  12.     int main(int argc, char** argv)
  13.         {
  14.  
  15.             int toggle=1;
  16.             int fd;
  17.            
  18.             //Write pin number to the export file
  19.             sysfs_write( "/sys/class/gpio/export","183");
  20.             //Set GPIO direction
  21.             sysfs_write( "/sys/class/gpio/gpio183/direction","out");
  22.             //Set Value
  23.             sysfs_write( "/sys/class/gpio/gpio183/value","1");
  24.            
  25.             for(;;)
  26.                 {
  27.                     toggle = !toggle;
  28.                    
  29.                     if (toggle)
  30.                         {
  31.                             sysfs_write("/sys/class/gpio/gpio183/value","1");
  32.                             printf("Current value: 1 \n");
  33.                         }
  34.                     else
  35.                         {
  36.                             sysfs_write("/sys/class/gpio/gpio183/value","1");
  37.                             printf("Current value: 0 \n");
  38.                         }
  39.                     sleep(1);
  40.                 }
  41.             return(0);
  42.                
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement