Data string adressing help please

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)

Please read the two posts at the top of this Forum for guidelines on posting here, especially the use of code tags when posting any code. Had you done so, you would have seen that you could have posted your source code so it was readable as part of the post rather than making us download it. Take the time to read those post and then edit your post using code tags.

  sensorValue [0] = digitalRead(inpin[0]);
  sensorValue [1] = digitalRead(inpin[1]);
  sensorValue [2] = digitalRead(inpin[2]);
  sensorValue [3] = digitalRead(inpin[3]);
  sensorValue [4] = digitalRead(inpin[4]);
  sensorValue [5] = digitalRead(inpin[5]);
  sensorValue [6] = digitalRead(inpin[6]);
  sensorValue [7] = digitalRead(inpin[7]);
  sensorValue [8] = digitalRead(inpin[8]);
  sensorValue [9] = digitalRead(inpin[9]);
  sensorValue [10] = digitalRead(inpin[10]);
  sensorValue [11] = digitalRead(inpin[11]);
  sensorValue [12] = digitalRead(inpin[12]);
  sensorValue [13] = digitalRead(inpin[13]);
  sensorValue [14] = digitalRead(inpin[14]);
  sensorValue [15] = digitalRead(inpin[15]);

You've got to be kidding.

  for (int i=0; i<= inputs; i++) {

If an array has sixteen elements, it's best not to iterate over all seventeen of them.

SO any assistance with my problem or are we going to just keep bagging the new guy...

SO any assistance with my problem or are we going to just keep bagging the new guy...

At least until he fixes the problems that are pointed out, and proves that they are not the root of the problem.

ghosty:
SO any assistance with my problem or are we going to just keep bagging the new guy...

A sketch that is a short as it needs to be (but no shorter) is easier to read and gives the bugs fewer dark corners to hide in.

A sketch that uses as little memory (all types) as possible (but no less) is less likely to bite you on the posterior.

ghosty:
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.

I can't figure from your code which part deals with the addressing issue that is causing a problem.

Can you explain what the code in sendALLsensors() is intended to do ?

You will make life much easier for yourself if you use a FOR loop to iterate over the reads in your readSensors() function

...R