(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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |