Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2024-04-19 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found