#!/usr/bin/perl # # This program displays a countdown of 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; } # # We count down from 9 to 0 in one second incruments. # $step = 9; while ($step >= 0) { if ($step == 0) { @display = (0,2,3,4,5,7); } elsif ($step == 1) { @display = (3,0); } elsif ($step == 2) { @display = (5,3,6,4,2); } elsif ($step == 3) { @display = (5,3,6,0,2); } elsif ($step == 4) { @display = (7,6,3,0); } elsif ($step == 5) { @display = (5,7,6,0,2); } elsif ($step == 6) { @display = (7,6,4,0,2); } elsif ($step == 7) { @display = (5,3,0); } elsif ($step == 8) { @display = (0,2,3,4,5,6,7); } elsif ($step == 9) { @display = (7,6,5,3,0); } # # Clear the LEDs. # for ($led=0;$led<=8;$led++) { $pp->set_bit($led, 0); } # # Now turn them on. # foreach $led (@display) { $pp->set_bit($led, 1); } # # Wait for one second before going on. # sleep 1; $step--; }