With the handy Device::BCM2835 package, I tossed together this little package so I could send "morse code" out on an LED I connected to GPIO Pins #5 and #7.

(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;


In reply to LED blinking Morse code from Raspberry Pi by rje

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.