Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use Device::BCM2835;
- use strict;
- # call set_debug(1) to do a non-destructive test on non-RPi hardware
- #Device::BCM2835::set_debug(1);
- Device::BCM2835::init()
- || die "Could not init library";
- # Blink pin 11:
- # Set RPi pin 11 to be an output
- Device::BCM2835::gpio_fsel(&Device::BCM2835::RPI_GPIO_P1_11,
- &Device::BCM2835::BCM2835_GPIO_FSEL_OUTP);
- my %code = (
- a => [\&dot, \&dash],
- b => [\&dash,\&dot,\&dot,\&dot,],
- c => [\&dash,\&dot,\&dash,\&dot,],
- d => [\&dash,\&dot,\&dot,],
- e => [\&dot,],
- f => [\&dot,\&dot,\&dash,\&dot,],
- g => [\&dash,\&dash,\&dot,],
- h => [\&dot,\&dot,\&dot,\&dot,],
- i => [\&dot,\&dot,],
- j => [\&dot,\&dash,\&dash,\&dash,],
- k => [\&dash,\&dot,\&dash,],
- l => [\&dot,\&dash,\&dot,\&dot,],
- m => [\&dash,\&dash,],
- n => [\&dash,\&dot,],
- o => [\&dash,\&dash,\&dash,],
- p => [\&dot,\&dash,\&dash,\&dot,],
- q => [\&dash,\&dash,\&dot,\&dash,],
- r => [\&dot,\&dash,\&dot,],
- s => [\&dot,\&dot,\&dot,],
- t => [\&dash,],
- u => [\&dot,\&dot,\&dash,],
- v => [\&dot,\&dot,\&dot,\&dash,],
- w => [\&dot,\&dash,\&dash,],
- # Turn it on
- Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 1);
- Device::BCM2835::delay($on); # Milliseconds
- # Turn it off
- Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 0);
- Device::BCM2835::delay($off); # Milliseconds
- }
- sub dot() {
- flash(200);
- }
- sub dash() {
- flash(400);
- }
- sub space() {
- Device::BCM2835::gpio_write(&Device::BCM2835::RPI_GPIO_P1_11, 0);
- Device::BCM2835::delay(500); # Milliseconds;
- }
- sub eom() {
- # ...-.-
- }
- while(my $line = <>) {
- my @letters = split( //, $line );
- foreach my $letter (@letters) {
- $letter = lc ($letter);
- next unless defined $code{$letter};
- foreach my $fn ( @{ $code{$letter} } ) {
- &$fn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement