I made this bit of code to follow it along and make sure the function was working OK. This just checks the reading each hour and generates a 24 hr. average temp. It seems to work fine, except I added a step to just take a point at the top of each hour. I was worried about the reading rewriting over and over again across an hour. Is there a limit to how often you can write over a memory space?
Code: Select all
#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>
#define DAILY_START 100 // start point for daily
#define AM_START DAILY_START + 48 // start point for weekly am
#define PM_START DAILY_START + 62 // start point for weekly pm
int daily[24];
int weekly_AM[7];
int weekly_PM[7];
int average;
int total;
byte mod;
void set_average(byte avg_array, int loc)
{
// avg_array: 0 = daily, 1 = weekly_am, 2 = weekly_pm
int mem_location;
switch ( avg_array )
{
default:
case 0: // daily average
{
daily[loc] = ReefAngel.Params.Temp[T1_PROBE];
mem_location = DAILY_START + (loc * 2);
break;
}
case 1: // weekly am average
{
weekly_AM[loc] = ReefAngel.Params.Temp[T1_PROBE];
mem_location = AM_START + (loc * 2);
break;
}
case 2: // weekly pm average
{
weekly_PM[loc] = ReefAngel.Params.Temp[T1_PROBE];
mem_location = PM_START + (loc * 2);
break;
}
}
InternalMemory.write_int(mem_location, ReefAngel.Params.Temp[T1_PROBE]);
}
int read_average(byte avg_array, int loc)
{
int mem_location;
switch ( avg_array )
{
default:
case 0: // daily average
{
mem_location = DAILY_START + (loc * 2);
break;
}
case 1: // weekly am average
{
mem_location = AM_START + (loc * 2);
break;
}
case 2: // weekly pm average
{
mem_location = PM_START + (loc * 2);
break;
}
}
return InternalMemory.read_int(mem_location);
}
void DrawCustomGraph()
{
}
void DrawCustomMain()
{
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,1,"0:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,11,"1:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,21,"2:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,31,"3:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,41,"4:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,51,"5:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,61,"6:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,71,"7:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,81,"8:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,91,"9:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,101,"10:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,3,111,"11:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,1,"12:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,11,"13:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,21,"14:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,31,"15:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,41,"16:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,51,"17:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,61,"18:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,71,"19:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,81,"20:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,91,"21:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,101,"22:");
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,55,111,"23:");
ReefAngel.LCD.DrawSingleMonitor(daily[0], COLOR_BLACK, 20, 1, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[1], COLOR_BLACK, 20, 11, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[2], COLOR_BLACK, 20, 21, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[3], COLOR_BLACK, 20, 31, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[4], COLOR_BLACK, 20, 41, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[5], COLOR_BLACK, 20, 51, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[6], COLOR_BLACK, 20, 61, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[7], COLOR_BLACK, 20, 71, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[8], COLOR_BLACK, 20, 81, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[9], COLOR_BLACK, 20, 91, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[10], COLOR_BLACK, 20, 101, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[11], COLOR_BLACK, 20, 111, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[12], COLOR_BLACK, 80, 1, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[13], COLOR_BLACK, 80, 11, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[14], COLOR_BLACK, 80, 21, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[15], COLOR_BLACK, 80, 31, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[16], COLOR_BLACK, 80, 41, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[17], COLOR_BLACK, 80, 51, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[18], COLOR_BLACK, 80, 61, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[19], COLOR_BLACK, 80, 71, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[20], COLOR_BLACK, 80, 81, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[21], COLOR_BLACK, 80, 91, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[22], COLOR_BLACK, 80, 101, 10);
ReefAngel.LCD.DrawSingleMonitor(daily[23], COLOR_BLACK, 80, 111, 10);
//average calculation
total=daily[0]+daily[1]+daily[2]+daily[3]+daily[4]+daily[5]+daily[6]+daily[7]+daily[8]+daily[9]+daily[10]+daily[11]+daily[12]+daily[13]+daily[14]+daily[15]+daily[16]+daily[17]+daily[18]+daily[19]+daily[20]+daily[21]+daily[22]+daily[23];
average = total / 24; // calculate the average:
mod=second() %2;
if (mod==0)
{
ReefAngel.LCD.Clear(255,5,121,132,132);
ReefAngel.LCD.DrawSingleMonitor(average, COLOR_BLUE, 55, 121, 10);
ReefAngel.LCD.DrawSingleMonitor(total, COLOR_BLUE, 95, 121, 10);
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T1_PROBE], COLOR_BLUE, 15, 121, 10);
}
else
{
ReefAngel.LCD.Clear(255,5,121,132,132);
ReefAngel.LCD.DrawDate(5,121);
}
}
void setup()
{
ReefAngel.Init();
// setTime (3,59,0,8,26,2012);
for (int a=0;a<24;a++)
{
daily[a]=read_average(0, a);
}
for (int a=0;a<7;a++)
{
weekly_AM[a]=read_average(1, a);
weekly_PM[a]=read_average(2, a);
}
}
void loop()
{
if (minute()==0 && second()<5)
{
if (now()%3600) set_average(0, hour());
if (now()%3600 && hour()==7) set_average(1, hour());
if (now()%3600 && hour()==19) set_average(2, hour());
}
ReefAngel.ShowInterface();
}