Hello,
I have this code that is supposed to monitor 7 pins for state change and all six analog pins, which eventually will be monitored for variation change. Anyway, the inputs are supposed to call the sendUpdate function which sends a GET request as a client. The remote web server then takes and stores the information to a database. I am having a problem that I am not sure how to solve the best way with the most accuracy. Quite often I will look through the database records and see many updates that were sent, but there is no change in the logic input states. So I assume that at the point of evaluation, there was a change but by the time it got sent to the sendUpdate function, it was back to the original state. Does that make sense? Here is my code...
Jeremy-arduino:
Quite often I will look through the database records and see many updates that were sent, but there is no change in the logic input states. So I assume that at the point of evaluation, there was a change but by the time it got sent to the sendUpdate function, it was back to the original state.
Updates without changes or
changes without updates?
Can't you log the cause (state change) of the updating?
The analogRead function is a long one.
With an oscope, or maybe an LED -- if you digitalWrite pin 13 HIGH, do your six analogReads, and then digitalWrite pin 13 LOW, you can get an idea of how long that's taking.
Using arrays and for loops to process the inputs would reduce the size of your code by roughly a factor of five.
The posted code seems to be incomplete - it's always best to post a complete sketch.
The technique used to detect input changes is unlikely to be effective (unless you have floating inputs, which would give you a whole other set of problems).
If you adopt arrays and for loops, you can address this easily by reading each input into a temporary variable and comparing with the previous stored value for that input before saving it. Here's the sort of thing I mean:
@ Runaway Pancake
Actually I have both issues. Updated records without change, and changes with up the update function running. I tried the flagbit, but that did not seem to fix anything.
@Arrch
That's what I would have thought too, and that's why I was almost too embarrassed to make this post, but I can't argue with the results.
@PeterH
That looks good, but as I'm not using consecutive pins, I am unsure how to implement that code.
Ideas on any of this anyone? If the full sketch is needed, I will post it...
I have measured the voltage at the pins and it is definitely going between 0-5 volts but the sendUpdate function is not running. How else can I troubleshoot this? I am using external pull up resistors...
OK, I looked at the StateChangeDetection and found what I was missing... I forgot to save the current to another "lastKnownState" variable. Doing that, fixed the problem and all works very well now... Thank you Arrch!!!