PDA

View Full Version : gcl+ scaning temperature during day



jueves
03-28-2012, 07:09 AM
Sorry if i posted this in the wrong place i was kinda in a hurry
GCL+ programming ....i have an temp sensor outside of the building, and i want to do an interval of values (for example i record temperature every hour) and than i need to do an average value of these temperatures....thanks

amsolo
03-29-2012, 10:45 AM
This code (from Delta Forum) creates 48 "bins" that store the temperature (AI1) each half-hour. Every 30 minutes it will re-compute the new average (DAYAVG). Note that this code won't work right until 24 hours goes by, because the empty "bins" will all have a value of 0.

// start of program

variable INDEX as integer
variable BINS[48] as real
variable LOOP as integer
variable SUM as real
variable DAYAVG as real

INDEX = limit(1 + truncate(decimaltime / 50), 1, 48)

If INDEX changed then
BINS[INDEX] = AI1

for LOOP = 1 to 48
SUM = SUM + BINS[LOOP]
End For
DAYAVG = SUM / 48
End If

// end of program