I'm not sure my title describes what I want to do here, but i'll try to explain.
At this point I am reading a sensor with my arduino board, where the arduino prints the sensor data properly in the serial connection. However I want to convert the sensor data in a more usable format. Let me show you:
Is there a way to program the arduino in such a way that it converts the data into this? I really only want to see the peak levels of each time the data peaks. This is probably basic beginner stuff, but I can't get it right myself.
Here is some pseudo code that I think handles the logic you want:
Initialise to zero three variables for holding values: NewValue, PrevValue, PeakValue;
For each NewValue:
If ( PrevValue equals zero and NewValue greater than zero ) or ( NewValue greater than PrevValue) then set PeakValue equal to NewValue
I hope that helps - please do post your code when you have it working
I think you will also need to reset PeakValue to zero when ever NewValue is at zero otherwise the peak value will only ever be the biggest value ever received.
In other words I think you will have to specify a decay on the PeakValue.
Hi Mike, I think he wants it to decay to any non zero value after at least one zero value is detected. The first half of the expression above should do this:
If( PrevValue equals zero and NewValue greater than zero ) then set PeakValue equal to NewValue
The example showing desired output never prints zero once an non zero value is detected