So as per this page http://arduino.cc/en/Main/arduinoBoardUno the Arduino UNO R3:
EEPROM is 1KB (1024 Bytes)
SRAM is 2KB (2048 Bytes)
If dtNBR_ALARMS allowable values is 0 to 255 MAX and
the RAM value as per the document is alarms * 11
a simple calculation using defaults (6 alarms set)
is 6 X 11 = 66 RAM (is this bytes ?? )
As you can see the documentation is not clear here
Q: How many alarms can be created?
A: Up to six alarms can be scheduled.
The number of alarms can be changed in the TimeAlarms header file (set by the constant dtNBR_ALARMS,
note that the RAM used equals dtNBR_ALARMS * 11)
Is this is indeed bytes the 255 X 11 = 2805 bytes
So just using an example of 1024 Bytes :
1024/11 = 93 alarms
Now lets say I want a device (yes a device can be anything that requires and on and off pulse.. strecth your mind here ...anything !!)
and this so called device is assigned a device ID (let's call this devID)
and each devID is assigned a number (as one probably would if you have lots of devices) like 465 (in other words LED number 465).
So devID 465
has:
an ON/START alarm
and OFF/END alarm
So to sum up each devID has two alarms linked/associated with it
(NOTE*** if we stretch our mind a little then a single device could have multiple alarms and patterns and delay patterns associated.)
So assuming on two alarms for each instance of devID the equation renders the following if 0 counts:
0-255 (256) /2 = 128 devices Max
and according to documentation the ram requirement for this is
128*11 = 1408 Bytes (? if this is bytes)
To be on the close to the 1024KB arduino UNO limit then a safe figure is 93 alarms
BUT
This does not take possible extra flags into operation.
We might need to flag an alarm to see if it is valid now after a power failure, not so ?
Of course if you are using a separate EEPROM then you could grow the max devices to to the MAX of 255.
So as per this document :
We see that :
If you have look-up tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values).
If you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword.
So going back to one of my earlier questions:
-
I would like to assign a start and end time to each device using its deviceID.
What would be the correct(or a nice) way to assign both an start and end time to each
single deviceID.
What is the correct/nice/most appropriate C/C++/C#/Arduino way to do this this ?
And before you answer, I would appreciate a stub of code to explain this or pseudo code to get me started or a pointer to an example coupled with an explanation of this if you wouldn't mind please.
I am not asking you to write my code for me I just want to be able to understand how and what the best method is.
@PaulS
Thanks for the replies and the first reply does add clarity to my earlier questions where I seem to have added a little fuzz into devID and the actual alarm, but later also refers to directly after create and not just after triggering ?
I would like to know how to reference the alarms after creating them.
-
How does once store the alarm ID's so you can reference them later. (I remember seeing a post
answered by PaulS somewhere in the last few days/weeks about this very same question but for
the life of me I can't remember the topic to search on.
You could store a copy of the object in EEPROM. But, it makes no sense to do that. You can't recreate an object in memory just by reading some bytes from EEPROM.
Yes I agree
So yes I need to store the start and end dates for each alarm ID in EEPROM and link those to the devID 465.
I have seen examples storing data into the EEPROM and retrieving it on the guides.
But what do I to (or how do I )make the link between devID and Alarm ID ?
Now, storing and retrieving the time that an alarm is supposed to go off might make sense.
Assuming that devID has two alarms associated with it , how do you do this in one foul swoop ?
So in conclusion...
How do I go about creating the link between a devID (which already exists for example devID 465) and the alarm ID's (assuming there are two alarm ID's for each devID ?
Is it an array ?
If I create something like this as a start (and please forgive my programming mistakes):
byte devID[128] =
OR
int devID[128] =
This could/would store the devID to two alarm ID's which in turn may or may not be stored in EEPROM not so ?
So devID needs to equal 2 alarm ID's
How do I link each devID with each devID ?
Would I be totally off the mark by thinking along these lines ?:
int alarmID = 1;//col
int stenAlarm = 2;//row
int[][] myArray = new int[alarmID][sten_alarm];
// For every alarmID i, for every start end alarm visit every row J.
for (int i = 0; i < alarmID; i++) {
for (int j = 0; j < stenAlarm; j++) {
myArray[i][j] = 0;
}
}
May work but how would I link the devID to the alarmID ?
Here's what I have in mind in pseudo code:
receive a devID (example here is 465)
create a start alarm, store it in arduino EEPROM and link this Alarm ID to the devID
create and end alarm, store it in arduino EEPROM and link this Alarm ID to the devID
Store each alarm time in EEPROM
I understand that devID should always link to two alarm ID's and each Alarm ID points to the time and date.
I also understand that devID 465 may point to Alarm ID 5 and 70.
So how do I keep this mapping correct ?
I also read that alarms can be reset or freed.
Please can somebody shed some light or assist me
Regards
JOE4444