Advertisement
AssazziN

Morse sender on GPIO

Mar 19th, 2013
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.69 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. $gpio=24;
  4. $delay=0.25;                   #Delay of send speed
  5. $pause=1*$delay;
  6. $dot_pause=1*$delay;
  7. $dash_pause=3*$delay;
  8. $character_pause=3*$delay;
  9. $word_pause=7*$delay;
  10.  
  11. print "\n [+]====================================[+]";
  12. print "\n  |   Send Morse Code On LED Wtih GPIO   | ";
  13. print "\n  |                                      | ";
  14. print "\n  |     GPIO Pin -> $gpio                   "; if ($gpio<9) { print " "; } print "| ";
  15. print "\n  |     Created By : AssazziN            | ";
  16. print "\n  |     Version : 1  [03/17/2013]        | ";
  17. #print "\n | http://comfeedom.blogspot.com | ";
  18. print "\n  |                                      | ";
  19. print "\n [+]====================================[+] ";
  20.  
  21. print "\n\n";
  22. print " Message >> ";
  23. chomp($text=<STDIN>);
  24. $original_text=$text;
  25. @original_text=split //,$original_text;
  26.  
  27. $text=~s/ /\//ig;
  28. $text=~s/\./.-.-.- /ig;
  29. $text=~s/,/--..-- /ig;
  30. $text=~s/\?/..-.. /ig;
  31. $text=~s/a/.- /ig;
  32. $text=~s/b/.--- /ig;
  33. $text=~s/c/-.-. /ig;
  34. $text=~s/d/-.. /ig;
  35. $text=~s/e/. /ig;
  36. $text=~s/f/..-. /ig;
  37. $text=~s/g/--. /ig;
  38. $text=~s/h/.... /ig;
  39. $text=~s/i/.. /ig;
  40. $text=~s/j/.--- /ig;
  41. $text=~s/k/-.- /ig;
  42. $text=~s/l/.-.. /ig;
  43. $text=~s/m/-- /ig;
  44. $text=~s/n/-. /ig;
  45. $text=~s/o/--- /ig;
  46. $text=~s/p/.--. /ig;
  47. $text=~s/q/--.- /ig;
  48. $text=~s/r/.-. /ig;
  49. $text=~s/s/... /ig;
  50. $text=~s/t/- /ig;
  51. $text=~s/u/..- /ig;
  52. $text=~s/v/...- /ig;
  53. $text=~s/w/.-- /ig;
  54. $text=~s/x/-..- /ig;
  55. $text=~s/y/-.-- /ig;
  56. $text=~s/z/--.. /ig;
  57. $text=~s/1/.---- /ig;
  58. $text=~s/2/..--- /ig;
  59. $text=~s/3/...-- /ig;
  60. $text=~s/4/....- /ig;
  61. $text=~s/5/..... /ig;
  62. $text=~s/6/-.... /ig;
  63. $text=~s/7/--... /ig;
  64. $text=~s/8/---.. /ig;
  65. $text=~s/9/----. /ig;
  66. $text=~s/0/----- /ig;
  67.  
  68. print " Sending >> $original_text[0]";
  69. $count_text=1;
  70. foreach (split //,$text) {
  71.     if ($_ eq '.') {
  72.         system("echo \"0\" > /sys/class/gpio/gpio$gpio/value");
  73.         select undef,undef,undef,$pause;
  74.         system("echo \"1\" > /sys/class/gpio/gpio$gpio/value");
  75.         select undef,undef,undef,$dot_pause;
  76.     }
  77.     elsif ($_ eq '-') {
  78.         system("echo \"0\" > /sys/class/gpio/gpio$gpio/value");
  79.         select undef,undef,undef,$pause;
  80.         system("echo \"1\" > /sys/class/gpio/gpio$gpio/value");
  81.         select undef,undef,undef,$dash_pause;
  82.     }
  83.     elsif ($_ eq ' ') {
  84.         system("echo \"0\" > /sys/class/gpio/gpio$gpio/value");
  85.         select undef,undef,undef,$character_pause;
  86.         print "$original_text[$count_text]";
  87.         $count_text++;
  88.     }
  89.     elsif ($_ eq '/') {
  90.         system("echo \"0\" > /sys/class/gpio/gpio$gpio/value");
  91.         select undef,undef,undef,$word_pause;
  92.         print "$original_text[$count_text]";
  93.         $count_text++;
  94.     }
  95.     else { print "\nERROR: $_\n"; exit; }
  96. }
  97. #http://comfreedom.blogspot.com/2013/03/raspberry-pi-morse.html
  98. print "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement