Go Down

Topic: Help with temperature controller (Read 1 time) previous topic - next topic

l0cke

I asked for help on this sketch a few days ago, in it's orginal topic:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187673287

After not reviving any help I tired to figure it out myself, and made some progress (I think?) but not anything really helpful. I am learning more about coding, but would like some help with this problem.

Quote
I'm trying to get this code to work. It seems to be incompatible with 0017.

This is the error I get
Code: [Select]
In function 'void loop()':
error: 'checkTemp' was not declared in this scope In function 'void toggle(Controller&)':


Here is the complete code from 2007
Code: [Select]
// Beer Thermostat

#define STATUS_OFF 0
#define STATUS_ON 1
#define TOGGLE_NOCHANGE 0
#define TOGGLE_ON 1
#define TOGGLE_OFF 2
#define TOGGLE_MALFUNCTION 3

#define WAIT 1000

struct Thermistor
{
 int  base; // *100, see below
 int  diff; // *10 because of floats (10.2, for example->102)
 int  pin;
};

struct Controller
{
 int  relayPin;
 int  thermInvert; // 0 = power on cools, 1 = power on heats
 int  lastRead;
 int  low;
 int  high;
 int  status; // 0=off;1=on
 int  toggle; // 0=nochange; 1=turnedon; 2=turnedoff; 3=malfunction
 int  timer;  // seconds since last status change
 struct Thermistor Therm; // Thermistor
};

Controller Freezer;
Controller Fermenter;

Thermistor ThermA;
Thermistor ThermB;

void setup()
{

 // Thermistor Calibration
 ThermA.base = 22500; // re-calibrate me!
 ThermA.diff = 102;
 ThermA.pin = 0;

 ThermB.base = 22500;
 ThermB.diff = 102;
 ThermB.pin = 1;

 // Freezer Setup
 Freezer.relayPin = 12;
 Freezer.low = 40; // (10 * ºC)
 Freezer.high = 60; // (10 * ºC)
 Freezer.thermInvert = 0;
 Freezer.status = STATUS_OFF;
 Freezer.toggle = TOGGLE_NOCHANGE;
 Freezer.timer = 0;
 Freezer.Therm = ThermB;

 // Fermenter Setup
 Fermenter.relayPin = 11;
 Fermenter.low = 170; // (10 * ºC)
 Fermenter.high = 180; // (10 * ºC)
 Fermenter.thermInvert = 1;
 Fermenter.status = STATUS_OFF;
 Fermenter.toggle = TOGGLE_NOCHANGE;
 Fermenter.timer = 0;
 Fermenter.Therm = ThermA;

 Serial.begin(9600);

 pinMode(Freezer.relayPin, OUTPUT);
 pinMode(Fermenter.relayPin, OUTPUT);
}

void loop()
{
 checkTemp(Freezer);
 toggle(Freezer);
 Freezer.timer++;
 doOutput("KEG", Freezer);

 delay(WAIT);

 checkTemp(Fermenter);
 toggle(Fermenter);
 Fermenter.timer++;
 doOutput("FER", Fermenter);

 delay(WAIT);

}

void checkTemp(struct Controller &c)
{
 int span = 20;
 int aRead = 0;
 for (int i = 0; i < span; i++) {
   aRead = aRead + analogRead(c.Therm.pin);
 }
 aRead = aRead / span;
 c.lastRead = (((1024 - aRead) * 100) - c.Therm.base) / c.Therm.diff; // ºC
}

void toggle(struct Controller &c)
{
 c.toggle = TOGGLE_NOCHANGE;
 if (c.lastRead > c.high && c.status != STATUS_ON) {
   // getting too hot
   tooHot(c);
 } else if (c.lastRead < c.low && c.status != STATUS_OFF) {
   // getting too cold
   tooCold(c);
 }
}

void tooCold(struct Controller &c)
{
 if (c.thermInvert) {
   digitalWrite(c.relayPin, HIGH);
   c.status = STATUS_ON;
   c.toggle = TOGGLE_ON;
 } else {
   digitalWrite(c.relayPin, LOW);
   c.status = STATUS_OFF;
   c.toggle = TOGGLE_OFF;
 }
 c.timer = 0;
}

void tooHot(struct Controller &c)
{
 if (c.thermInvert) {
   digitalWrite(c.relayPin, LOW);
   c.status = STATUS_OFF;
   c.toggle = TOGGLE_OFF;
 } else {
   digitalWrite(c.relayPin, HIGH);
   c.status = STATUS_ON;
   c.toggle = TOGGLE_ON;
 }
 c.timer = 0;
}

void doOutput(char name[4], struct Controller &c)
{
 Serial.print(name);
 Serial.print(" ");
 Serial.print(c.lastRead);
 Serial.print(" ");
 Serial.print(c.status);
 Serial.print(" ");
 Serial.print(c.toggle);
 Serial.print(" ");
 Serial.println(c.timer);
}





What do I need to do to make this work with my arduino? I'll make sure to update this topic if I figure it out on my own  :)

mem

#1
Sep 05, 2009, 09:37 am Last Edit: Sep 05, 2009, 09:39 am by mem Reason: 1
Arduino automatically creates prototypes for each function but it does not handle user defined arguments (such as your structures) which is why your code wont compile. You can fix that by adding the prototypes yourself, just after the struct definitions - here is a fragment that has prototypes for the functions that take your structures:

Code: [Select]
struct Thermistor
{
 int  base; // *100, see below
 int  diff; // *10 because of floats (10.2, for example->102)
 int  pin;
};

struct Controller
{
 int  relayPin;
 int  thermInvert; // 0 = power on cools, 1 = power on heats
 int  lastRead;
 int  low;
 int  high;
 int  status; // 0=off;1=on
 int  toggle; // 0=nochange; 1=turnedon; 2=turnedoff; 3=malfunction
 int  timer;  // seconds since last status change
 struct Thermistor Therm; // Thermistor
};

// add the prototypes here:
void checkTemp(struct Controller &c);
void toggle(struct Controller &c);
void tooHot(struct Controller &c);
void tooCold(struct Controller &c);
void doOutput(char name[4], struct Controller &c);



Go Up