#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow(); my %STATE=( 'lights'=>0, 'bell'=>0 ); my %ENABLE=( 'lights'=>144, 'bell'=>136, 'lights&bell' => 144|136, # not sure here 'nothing' => 128 # enable nothing ); my $lights; my $bell; # Exit-Button my $message = $mw->Entry()->pack; $mw->Button(-text=>'End', -command=>sub {exit} )->pack; $lights = $mw->Button(-text=>'Turn LIGHTS on', -command=>sub { # toggle lights $STATE{'lights'} = 1 - $STATE{'lights'}; # can also do != # send data to turn on/off lights calculateInstruction(); $lights->configure(-text => 'Turn LIGHTS '.($STATE{'lights'}?'off':'on')); updateMessage(); } )->pack; $bell = $mw->Button(-text=>'Turn BELL on', -command=>sub { # toggle lights $STATE{'bell'} = 1 - $STATE{'bell'}; # can also do != # send data to turn on/off lights calculateInstruction(); $bell->configure(-text => 'Turn BELL '.($STATE{'bell'}?'off':'on')); updateMessage(); } )->pack; sub calculateInstruction{ my $n; if($STATE{'lights'} && $STATE{'bell'}){ $n = $ENABLE{'lights&bell'} }elsif($STATE{'lights'}){ $n = $ENABLE{'lights'} }elsif($STATE{'bell'}){ $n = $ENABLE{'bell'} }else{ $n = $ENABLE{'nothing'} } my $instruction = ""; print "Would send $instruction to serial\n"; # $port->write($instruction); # $port->lookclear(); } sub updateMessage{ my $msg = 'LIGHTS='.$STATE{'lights'}." BELL=".$STATE{'bell'}; $message->configure(-text => $msg); } MainLoop;