I'm working on a controller for my floor heating. Each room has his own thermostat ( on/off)
The controller has to control the magnetic valves, the boiler and the pump for the floor heating.
My sketch is working with the use of the delay() function.
Now I want to modify this sketch so that the program does not stops for the delay().
I've tried this based on the examples with millis(), but it doesn't work.
How can I solve this problem ?
Please post your best effort at using millis() for timing, using code tags when you post it
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination
If you ask for help, please change to using meaningful names for variable, etc. People usually can't follow someone elses acronyms and abbreviations. No need for short names.
Define an object with the I/Os, time control once and use this multiple times for each room.
As already mentioned, do not use any magic abbreviations or numbers. The comments in the sketch use great designations that can be used as variable names.
is a many letters using acronym, that hides away a lot of knowledge which requires to learn dozens of hours about medium advanced programming techniques!
@guyc1
here is a video-tutorial that explains how non-blocking timing based on millis() works
First of all my excuses for my late answer, but I was away the whole day and had no time to read my emails and to play with arduino.
I want to do 2 things :
Starting from the position that there is no heat demand ( all thermostats open contact), when the first thermostat ask heat, his magnetic valve has to open. Because the opening time for this type of valves is 2 minutes, the controller has to wait 2 minutes befor the boiler and the pump is started.
When their is no heat demand anymore, the boiler must be stopped and to send the heat stil present in the boiler, has to be in service for 1 minute after the last thermostat is off.
The original sketch I made with the delay() function is working well, but the arduino has to handle also alarms later on. For that reason it should be fine to replace the delay() function with a routine based on millis().
How can I thank you.
Based on your first sketch, I was trying to program the boiler and pump delay. but then I saw your latest version. This is it.
Anyway, I learned a lot.
You need to be careful using this. sizeof gives you the size of the array, not the number of elements in it. It only works in your sketch because you are using it on an array of 1-byte elements. If you change the type of the array (or copy-and-paste it to use with a different array), it might not work. The general way to get the number of elements in an array like this is to take the sizeof the full array and divide it by the sizeof one element of the array.
sizeof(array) / sizeof(array[0])
This will always work no matter what type the array is. You can even define a preprocessor macro function to do this for you
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
const int Nrelay = ARRAY_SIZE(PinRelay);