in reply to Saving Options

Here's some code that I based on the links below with changes for the values you gave for F0 and F1. (It sounds like yours is wired in a better fashion than theirs.) It's a subroutine for calculating the command to send.

#!/bin/env perl use strict; use warnings; use List::Util qw(sum0); use List::MoreUtils qw(uniq); { my %buttons = ( '0' => 16, '1' => 8, '2' => 4, '3' => 2, '4' => 1, ); sub buttonsPressed { my ($cab, @pressed) = @_; my @values = map { 0 + $buttons{$_} } uniq @pressed; return sprintf "<f %d %d>", $cab, 128 + sum0 @values; # Yes, these + two lines could be combined } } my $cab = 1108; my @tests = ( [ 0 ], [ 1 ], [ 2 ], [ 0, 1 ], [ 0, 2 ], [ 1, 2 ], [ 0, 1, 2 ], ); for my $test ( @tests ) { print "@{$test} : ", buttonsPressed( $cab, @{$test} ), "\n"; } __END__ 0 : <f 1108 144> 1 : <f 1108 136> 2 : <f 1108 132> 0 1 : <f 1108 152> 0 2 : <f 1108 148> 1 2 : <f 1108 140> 0 1 2 : <f 1108 156>

Related links?

Replies are listed 'Best First'.
Re^2: Saving Options
by PilotinControl (Pilgrim) on Dec 22, 2015 at 12:14 UTC

    That is correct...I am part of that group on TrainBoard talking about DCC Plus and the person coding the base station and controller code uses Java and Win32-Serial is what I use to communicate with the Arduino while others are using JMRI etc. So far everything I've been doing has been working out very well in communicating with decoders etc.