Advertisement
AssazziN

[Raspberry Pi] GPIO Control

Mar 19th, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.84 KB | None | 0 0
  1. print "\n [+]----------------------------------------[+]";
  2. print "\n  |    GPIO Control by using perl on bash    |";
  3. print "\n  |      Test on Raspbian Wheezy [RPi]       |";
  4. print "\n  |                                          |";
  5. print "\n  |   Created by : AssazziN                  |";
  6. print "\n  |   Version 1: 11 Mar 2013                 |";
  7. print "\n [+]----------------------------------------[+]\n";
  8.  
  9. print "\n >> type h|help for help\n";
  10. do {
  11.     print " >> ";
  12.     chomp($input=<STDIN>);
  13.     if ($input eq 'h' or $input eq 'help') { help(); }
  14.  
  15.     elsif ($input=~/^export (\d{1,2})$/) {
  16.         system("echo \"$1\" > /sys/class/gpio/export");
  17.     }
  18.  
  19.     elsif ($input=~/^direction (\d{1,2}) (out|in)$/) {
  20.         system("echo \"$2\" > /sys/class/gpio/gpio".$1."/direction");
  21.     }
  22.  
  23.     elsif ($input=~/^value (\d{1,2}) (1|0)$/) {
  24.         system("echo \"$2\" > /sys/class/gpio/gpio".$1."/value");
  25.     }
  26.  
  27.     elsif ($input=~/^unexport (\d{1,2})$/) {
  28.         system("echo \"$1\" > /sys/class/gpio/unexport");
  29.     }
  30.  
  31.     elsif ($input=~/status/i) {
  32.         @pin=();
  33.         $pin=`find /sys/class/gpio/ gpio*`;
  34.         while ($pin=~/sys\/class\/gpio\/gpio(\d{1,2})/g) { push(@pin,$1); }
  35.         print " All pins that useabled : @pin\n";
  36.     }
  37.  
  38.     elsif ($input eq 'q' or $input eq 'quit' or $input eq 'exit') {}
  39.     else { print " $input : command not found\n"; }
  40. } while ($input ne 'q' and $input ne 'quit' and $input ne 'exit');
  41.  
  42.  
  43.  
  44. sub help {
  45.     print "\n ** This script requirement ROOT ***\n";
  46.     print " > export [GPIO PIN]                 set gpio pin to useable\n";
  47.     print " > direction [GPIO PIN] [out|in]     set gpio pin direction\n";
  48.     print " > value [GPIO PIN] [1|0]            set gpio pin value\n";
  49.     print " > unexport [GPIO PIN]               set gpio pin to unuseable\n";
  50.     print " > status                            check status of all pin\n";
  51.     print " > q quit exit                       exit script\n\n";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement