(FYI: the Raspberry Pi can run a number of Linux systems, all with Perl. I wrote a tiny HTTP server on it which lets me create and serve Commodore disk images, also allowing me to extract and inject files, in Perl of course. It runs behind my firewall...)
package GPIO; use strict; use Device::BCM2835; Device::BCM2835::init() || die "Error initializing BCM2835 interface.\ +n"; sub new { bless {}, shift } my @pins = ( &Device::BCM2835::RPI_V2_GPIO_P1_07, &Device::BCM2835::RPI_V2_GPIO_P1_11, &Device::BCM2835::RPI_V2_GPIO_P1_12, &Device::BCM2835::RPI_V2_GPIO_P1_13, &Device::BCM2835::RPI_V2_GPIO_P1_15, &Device::BCM2835::RPI_V2_GPIO_P1_16, &Device::BCM2835::RPI_V2_GPIO_P1_18, &Device::BCM2835::RPI_V2_GPIO_P1_22 ); # Set pins to be outputs. foreach my $pin ( @pins ) { Device::BCM2835::gpio_fsel( $pin, &Device::BCM2835::BCM2835_GPIO_FS +EL_OUTP ); } sub dit { my $gpio4 = $pins[0]; Device::BCM2835::gpio_write( $gpio4, 1 ); Device::BCM2835::delay( 80 ); Device::BCM2835::gpio_write( $gpio4, 0 ); Device::BCM2835::delay( 50 ); } sub dah { my $gpio4 = $pins[0]; Device::BCM2835::gpio_write( $gpio4, 1 ); Device::BCM2835::delay( 240 ); Device::BCM2835::gpio_write( $gpio4, 0 ); Device::BCM2835::delay( 50 ); } sub key { foreach (split '', shift) { dit() if /\./; dah() if /-/; Device::BCM2835::delay( 150 ) if /\s/; } Device::BCM2835::delay( 400 ); } sub word { foreach ( split '', shift ) # letters { print "$_\n"; key( '.-' ) if /a/i; key( '-...' ) if /b/i; key( '-.-.' ) if /c/i; key( '-..' ) if /d/i; key( '.' ) if /e/i; key( '..-.' ) if /f/i; key( '--.' ) if /g/i; key( '....' ) if /h/i; key( '..' ) if /i/i; key( '.---' ) if /j/i; key( '-.-' ) if /k/i; key( '.-..' ) if /l/i; key( '--' ) if /m/i; key( '-.' ) if /n/i; key( '---' ) if /o/i; key( '.--.' ) if /p/i; key( '--.-' ) if /q/i; key( '.-.' ) if /r/i; key( '...' ) if /s/i; key( '-' ) if /t/i; key( '..-' ) if /u/i; key( '...-' ) if /v/i; key( '.--' ) if /w/i; key( '-..-' ) if /x/i; key( '-.--' ) if /y/i; key( '--..' ) if /z/i; key( ' ' ) if /\s/i; } } 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: LED blinking Morse code from Raspberry Pi
by choroba (Cardinal) on Aug 30, 2014 at 19:28 UTC | |
Re: LED blinking Morse code from Raspberry Pi
by zentara (Cardinal) on Aug 31, 2014 at 08:52 UTC | |
by afoken (Chancellor) on Aug 31, 2014 at 11:09 UTC | |
by morgon (Priest) on Aug 31, 2014 at 13:50 UTC | |
by rje (Deacon) on Sep 01, 2014 at 21:27 UTC | |
by zentara (Cardinal) on Sep 02, 2014 at 08:09 UTC | |
Re: LED blinking Morse code from Raspberry Pi
by rje (Deacon) on Sep 10, 2014 at 01:27 UTC | |
Re: LED blinking Morse code from Raspberry Pi
by rje (Deacon) on May 03, 2021 at 14:47 UTC | |
Re: LED blinking Morse code from Raspberry Pi
by wjw (Priest) on Dec 06, 2014 at 01:36 UTC | |
by Lotus1 (Vicar) on Dec 08, 2014 at 22:39 UTC |