Using qsort to average readings

OK @BulldogLowell, please understand I am a 62 years old young man who started programming (C++) one year ago… During my university days (1973 - 1977), we programmed in “Pascal”, using paper cards with pencil written codes…
English is only my 4th language, which explains maybe my strange vocabulary like “pulses” which you seem not to understand. :wave: :older_man:

Some background about what I’m trying to achieve:

What I’m trying to develop is a complete home automation system for 2 adjacent homes (my son and us) , with 16 rooms, where in each room a Photon is used to receive signals of all sensors in the room and control all actuators in the room. Then all Photons in both houses talk to each other to exchange data from sensors and commands for actuators. In fact, a “distributed” home-automation system" instead of the classic “centralized home automation system”.

A big portion of my efforts goes towards organizing the energy flow in our “eco” heating system:

I appreciate your above tip to save one line in my sketch!
How I love to learn “good practice” tricks…

But what I really want to do in my sketches, is put as much as possible all commands in my functions, instead of putting it in the setup() or loop() function.

The reason is that I want to be able to combine the building blocks more simply in my “room sketches” by using functions from my “library” into more complex sketches, where I would call the functions from the loop() function.

Is that not good practice?

The sketch I pasted above is not yet a finished sketch, as it is only to test the temperature sensors, at that time PWM type output sensors (3 kHz HI & LOW “pulses”). Since then I changed my mind to use one-wire sensors…

The only reason I pasted the sketch is to see how I could use the “qsort” command to simply sort the data in my array and create a “median filter”. @Ric gave me a good idea how to do this, and I’ll try it out with every sensor from now on.

I hope you understand my sketch better now. :relaxed:

1 Like