I added the digitalRead in the String and it is only triggering once, I have triggered it everytime I trigger the prox so the prox value and photoeye should be equal.
The point is, the way you are doing this the trigger has to happen at the exact time your are calling PublishLaneCount(). You are publishing whether there currently is a trigger active when you publish or not.
I guess this is not what you want.
Do you not rather want to count the triggers into your array LaneCount[] and then after some time collecting data publish the content of that very array - instead of the current pin states?
BTW, in C/C++ there is a neater way to write this
LaneCount[i] = LaneCount[i] + 1;
You’d just write
LaneCount[i]++; // post increment (in an expression the current value is evaluated first and incremented after)
// or
++LaneCount[i]; // pre increment (in an expression the value is incremented first and then evaluated)
// or
LaneCoune[i] += 1; // this is handy when incrementing for other values than 1
// just replace the 1 with whatever you want - even a variable
The void loop() {} really moves or cycles, zoom zoom… I have a similar application where I use a latch bit for the LOW or HIGH pin state which triggers a Count of 1 to keep the loop’s speed from counting each cycle… Once the input pin returns to the non-trigger state, I reset the latch bit… In my app, I also use an onDelay or Debounce timer using millis() when I compare an analog input to a set point or to keep a level switch from triggering while bouncing on/off. @dtuttoil: Just curious, are the Photos discretes?
So now that I have this code working correctly, I’m wondering if anyone has suggestions on the best platform to use to display this data. For testing we’ll be installing these control boxes on 6 machines. I’ll need the ability to reset the photons remotely and to monitor data. I was looking at the Losant platform.