Hi
I am trying to convert an address in my Arduino project and export it to Loconet (model train network) There are a couple of working sketchs I have found on the net that can do this but they are all limited to 255 max output address to loconet.
Loconet can handle far greater addressing, and indeed my method below gets into the 4000 range when I attempt it but I am doing something wrong. My starting address is 495, i would expect 495 in loconet, if I use a sub 255 adress I get the correct response in loconet.
But using an address above 255, such as my test address of 496, on loconet I get a result of 4096 from this resulting code. typically as soon as i put either the hibyte or the temp address into the byte2,5 and there after I start my addressing at 2048 and then it adds the portion of the address over 255 to that value.
hiByte = highByte(tempaddr); // take tempaddr strip out MS bits and store in value "hiByte"
loByte = lowByte(tempaddr); // take tempaddr strip out LS bits and store in value "loByte"
int H = tempaddr / 255 ; // just tring an alternative to Hi / Lo byte
int L = (tempaddr - (255*H)); // as above
// build the two packets and set their respective bits.
byte1 = tempaddr;
byte1 = byte1 >> 1;
bitClear (byte1,7);
bitSet (byte2,6);
bitWrite (byte2,5, bitRead(tempaddr,7)); // not sure if this shoudl be hiByte or just left off altogether.
bitWrite (byte2,3, bitRead(tempaddr,6)); //added to hope to write MS bits
bitWrite (byte2,2, bitRead(tempaddr,5));
bitWrite (byte2,1, bitRead(tempaddr,4));
bitWrite (byte2,0, bitRead(tempaddr,3));
bitWrite (byte2,4, sensorValue); // sets the L value
// bitWrite (byte2,3, bitRead(hiByte,0)); // stes the 4 MS bits..this is what we where missing.
sendTXtoLN (byte1, byte2); //send the constructed packets to the loconet.
below is the data string loconet is looking for direct cut paste from there doco.
OPC_INPUT_REP 0xB2 ; General SENSOR Input codes NO
; <0xB2>, , ,
=<0,A6,A5,A4- A3,A2,A1,A0>, 7 ls adr bits. A1,A0 select 1 of 4 inputs pairs in an DS54
=<0,X,I,L- A10,A9,A8,A7> Report/status bits and 4 MS adr bits.
I=0 for DS54 "aux" inputs and 1 for "switch" inputs mapped to 4K SENSOR space.
(This is effectively a least significant adr bit when using DS54 input configuration)
L=0 for input SENSOR now 0V (LO) , 1 for Input sensor >=+6V (HI)
X=1, control bit , 0 is RESERVED for future!
I have only been playing with Arduino for the past 3-4 months on and off, so I am no moderate programmer I consider myself still to be a beginner so I am looking for some assistance to help me solve this.
Attached is my full sketch and the loconet library .
Thanks in advance
Ty
Loconet_intput_card_r2.1_longADD.ino (8.33 KB)
LocoNet.zip (52.1 KB)