I got the sketch running using progmem, but not without issues though. The sketch is a webremote the works with two html buttons to turn on and off certain pins. Controlling two buttons is no problem. Three buttons: problems. Four Buttons; more problems. With three buttons, I can click a button to turn on a pin and the sketch will continue to loop. But if I click the button again to turn off the pin the sketch freezes and I have to reset the arduino. With four html buttons, the sketch will continue to run but the buttons do nothing. Here is the sketch so far:
#include <EEPROM.h>
#include "etherShield.h"
#include "ETHER_28J60.h"
#include <avr/pgmspace.h>
#include "DHT.h"
#include "Wire.h"
#include "LiquidCrystal.h"
#define DHTPIN1 A0
#define DHTPIN2 A1
#define photocellPin A3
#define fanPin 2
#define valvePin 3
#define ventPin 4
#define motorRun 5
#define motorReverse 6
#define ethernet_cs 10
#define DaylightThreshold 100
#define DHTTYPE DHT11
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
int photocellReading;
unsigned long interval = 3000;
unsigned long mistTime = 7000;
unsigned long ventTime = 30000;
unsigned long fanTime = 300000;
unsigned long previousMillis = 0;
unsigned long previousMistTime = 0;
unsigned long previousFanTime = 0;
unsigned long previousMotorRuntime = 0;
unsigned long previousVentTime = 0;
int repetitionCounter = 0;
LiquidCrystal lcd(0);
static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0xA0, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {
192, 168, 1, 15}; // IP address for the webserver
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
prog_char string_0[] PROGMEM = "<h1><a href='/?valve=off'>Greenhouse Arduino</a></h1>"; // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "
";
prog_char string_2[] PROGMEM = "Brightness: ";
prog_char string_3[] PROGMEM = "Failed to read from DHT";
prog_char string_4[] PROGMEM = "Humidity: ";
prog_char string_5[] PROGMEM = " Temperature: ";
prog_char string_6[] PROGMEM = "Time since last misting cycle: ";
prog_char string_7[] PROGMEM = "Window vent is OPEN.";
prog_char string_8[] PROGMEM = "Window vent is closed.";
prog_char string_9[] PROGMEM = "<button type='button' onclick=location.href='?valve=off'>VALVE</button>";
prog_char string_10[] PROGMEM = "<button type='button' onclick=location.href='?fan=off'>FAN</button>";
prog_char string_11[] PROGMEM = "<button type='button' onclick=location.href='?vent=off'>VENT</button>";
prog_char string_12[] PROGMEM = "<button type='button' onclick=location.href='?window=off'>WINDOW</button>";
prog_char string_13[] PROGMEM = "<a href='?valve=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>VALVE IS ON</button></a>";
prog_char string_14[] PROGMEM = "<a href='?valve=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>VALVE IS OFF</button></a>";
prog_char string_15[] PROGMEM = "<a href='?fan=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>FAN IS ON</button></a>";
prog_char string_16[] PROGMEM = "<a href='?fan=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>FAN IS OFF</button></a>";
prog_char string_17[] PROGMEM = "<a href='?window=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>WINDOW IS ON</button></a>";
prog_char string_18[] PROGMEM = "<a href='?window=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>WINDOW IS OFF</button></a>";
prog_char string_19[] PROGMEM = "<a href='?vent=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>VENT IS ON</button></a>";
prog_char string_20[] PROGMEM = "<a href='?vent=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>VENT IS OFF</button></a>";
prog_char string_21[] PROGMEM = " minutes";
PROGMEM const char *string_table[] =
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
string_14,
string_15,
string_16,
string_17,
string_18,
string_19,
string_20,
string_21};
char buffer[155];
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void setup()
{
dht1.begin();
lcd.begin(16, 2);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, INPUT);
digitalWrite(7, HIGH);
//pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
for (int i = 0; i < 6; i++)
EEPROM.write(i, 0);
EEPROM.write(7, 100); // repetitions
e.setup(mac, ip, port);
Serial.begin(57600);
Serial.println(F("\n[memCheck]"));
Serial.println(freeRam());
}
void loop()
{
processClient();
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
checkHumidty();
checkTemp();
printConditions();
repetitionCounter++;
}
checkMistingTime();
checkFanTime();
checkVentingTime();
checkWindowMotorRuntime();
checkWindowVentState();
//Serial.println(repetitionCounter);
}
}