#!/usr/bin/perl # # This program displays numbers using 7 segment # LEDs driven from a PC's parallel port. LEDs are # hooked to the data pins (2-9) with 470 ohm resistors # and then to a ground pin (18-25). # # This assumes that the pins turned on will stay on... # # I've written a version of this program that # displays patterns in a loop instead, # if your interested take a look here: # # http://www.anderbergfamily.net/ant/ledcontrol/ # # Version 1.0 - 12/23/2007 # by Anthony Anderberg ant@anderbergfamily.net # # # Scott Penrose's parallel port direct-control module, # needed for direct port access. # On Win32 systems this requires inpout32.dll # use Device::ParallelPort; my $pp = Device::ParallelPort->new('auto:0'); if (!defined($pp)) { print "\nParallel port setup error: \n $! \n"; exit; } # # Most of the time the data ports are all # 'on' to begin with, we'll turn them off. # for ($step=0;$step<=8;$step++) { $pp->set_bit($step, 0); } # # First we setup which LEDs to turn on, # and will depend on how what order you've # wired your LEDs. They are counted starting # with 0 and going to 7 - counting the 7 # segments and the dot for a total of 8 LEDs. # if ($ARGV[0] eq '') { @display = (); print "Usage: displaynum \n"; } elsif ($ARGV[0] eq '0') { @display = (0,2,3,4,5,7); } elsif ($ARGV[0] eq '1') { @display = (3,0); } elsif ($ARGV[0] eq '2') { @display = (5,3,6,4,2); } elsif ($ARGV[0] eq '3') { @display = (5,3,6,0,2); } elsif ($ARGV[0] eq '4') { @display = (7,6,3,0); } elsif ($ARGV[0] eq '5') { @display = (5,7,6,0,2); } elsif ($ARGV[0] eq '6') { @display = (7,6,4,0,2); } elsif ($ARGV[0] eq '7') { @display = (5,3,0); } elsif ($ARGV[0] eq '8') { @display = (0,2,3,4,5,6,7); } elsif ($ARGV[0] eq '9') { @display = (7,6,5,3,0); } elsif ($ARGV[0] eq '.') { @display = (1); } else { print "Unsupported character: $ARGV[0]\n"; } # # Now turn them on. # foreach $led (@display) { $pp->set_bit($led, 1); }