Hello, Can someone guide me how to load a table of 365*2 bytes entries? I want to load the sunrise and sunset times in my location at a given area of the flash. Thanks!
It sounds like yo need a 2 dimensional array, 1 row per day and 2 columns for sunrise and sunset, but be careful because you may not have enough memory
What data type will the values be ?
What are the max and min values of each entry ?
Please give some examples of the values
Will the values ever be changed by the program (unlikely, but possible) ?
in my location, taking into account dst shifts we have
setMin= 4:37, setMax=7:52 => setMid=6:11 and deltaMax=94'
riseMin=5:37, riseMax=6:56, riseMid=6:16, deltaMax=40'
so both values fit in a byte, we can organise the table as
an_even_location - deltaRise1stJan
the_evenLocation+1 - deltaSet1stJan
...
We can have doy variable (day of year) out of RTC's epoch
and two constants doy_start_dst and dot_end_dst
I am not sure how you reach that conclusion. What units are you measuring the times in ?
riseMin 5:37 riseMax 6:56 from the table
rise mid = (min+max)/2. delta in minutes (noted ') = max distance from mid.
Sorry, you are right: delta is a relatif number(!) so We can keep the min (constant number) and distance from min
setMin=4.37, setMax=7:52; max distance =7:52-4.37=3:14 =194' which fit in a byte
riseMin=5:37, riseMax=6:56; max distance=6:56-5:37=1:19=79' which again fit in a byte
How do you preview with this new i/f?
I am sorry but I still don't know what format you want to store the data in. The sunrise and sunset look like strings, which could make using them more difficult than if they were say minutes, or even seconds since midnight
As you are replying there is a live preview to the right like this
Preview:
I only have the right box. Nothing to the left
Table
e.g. rise. - we want to store numbers which are the distance in minutes from the earliest rise. This fit in a byte
Suppose we want to know when to turn off home entrance light (or disable the entrance PIR)
we get doy from RTC. this starts at 1 up to 365
we shoot to the flash at address tableStart+2*(doy-1) (for set it'd be 2*(doy-1)+1) and get how many minutes from earliest rise
we add it to earliest rise (integer in minutes from 0 to 24*60=1439) which is a constant for a given geo coordinates given planet
we get 'rise' in minutes from midnight. If our on board RTC minute > 'rise' than turn off / disable PIR
How about something like this ?
const byte timeData[5][2] PROGMEM =
{
{10, 50}, //just 5 days of dummy data for now
{12, 60},
{14, 65},
{18, 70},
{22, 77}
};
void setup()
{
Serial.begin(115200);
while (!Serial);
for (int dayNumber = 0; dayNumber < 5; dayNumber++)
{
byte sunrise = pgm_read_byte_near(*timeData + (dayNumber * 2));
byte sunset = pgm_read_byte_near(*timeData + (dayNumber * 2) + 1);
Serial.print("day number ");
Serial.print(dayNumber);
Serial.print("\tsunrise ");
Serial.print(sunrise);
Serial.print("\tsunset ");
Serial.println(sunset);
}
}
void loop()
{
}
In a word ...
It's fantastic!!!!!!!!!!!!!!!!!!!!!!
Thank you
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
