Controlling Alpha LED Signs with Perl or PHP in Windows
October 13, 2008 – 10:02 pmI acquired an Alpha LED sign in a '$1 it's broke' Ebay action. Using my undergrad EE skills, I replaced the fuse and had a working sign.
(Also note some of my totally awesome collection of Internet Appliances)
Thing is, I have nothing to use it for. I was going to make it web accessible so random people could change the message, but that would require me to leave my computer on all of the time and my bandwidth free.
It's a easy project really. You need a form to collect the messages and place them in a database. Then you need another script that runs every X minutes, grabs the oldest unsent message from the DB and sends it to the sign. Then you snap a webcam photo. %90 of that code is in the PHP script below.
All of the real work for sending messages to the sign was done by this guy. He even has instructions on how to make the serial cable for the sign. All I did was figure out how to get at the serial port in Windows. It took a bit of mad Googling.
Perl:
#!C:\Perl\bin\wperl.exe $com_port = 'COM1'; $style = $ARGV[0]; if($style eq 'flash') { $stlye = 'c'; } elsif($style eq 'random') { $style = 'd'; } elsif($style eq 'scroll') { $style = 'a'; } elsif($style eq 'random') { $style = 'd'; } elsif($style eq 'shrink') { $style = 't'; } else { $style = 'a'; } $message = $ARGV[1]; if(!$message) { $message = "Dude, my balls are freakin' huge."; } # LINUX: open( PORT, ">/dev/ttyS0" ) open( PORT, "+>COM1" ) or die "Can't open COM1: $!"; print PORT "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; print PORT "\001" . "Z" . "00" . "\002" . "AA" . "\x1B" . " $style " . $message . "\004"; close(PORT); print "Sent: $message\n";
PHP:
If you're the brave sort, you can call this from a browser. It uses VFW Grab to snap a webcam picture after the message is displayed.
<?PHP $style = 'w'; $message = (isset($_GET['message']) ? $_GET['message'] : 'Boobs?'); // LINUX: $fh = fopen("/dev/ttyS0", "wb") or die("can't open port"); $fh = fopen("COM1", "wb") or die("can't open port"); fwrite($fh, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); fwrite($fh, "\001" . "Z" . "00" . "\002" . "AA" . "\x1B" . " $style " . $message . "\004"); fclose($fh); system("VFWGrab.exe"); print "Sent: $message"; print "<br><img src=capture.jpg>"; ?>
On another note, a stick bug was being sticky in my garden this morning.
