Help with map()

Hi Guys,

I am hopeing someone can help me out. I am new to Arduino and am working on a code to vary a light startup based on month and day from a RTC.

Basicly I need to make a map that will do the following;

on Jan 1, start at 4:56
and on Jan 31st start at 5:20

With a map to calculate the start time between the two days.

Thanks,

Jason

if (month == 1) { map janStart (day = 1 min at 296 day = 31 at max 320) }

and return that value as janStart

Somthing like that, the months are returned as 1 - 12 and the days 1 - 28 - 31 depending on month.

Its problaby not that complicated but I just cant get my head around map() with the examples given.

Cheers,

Jason

would it just be this?

if(month == 1) { janStart = map(day, 1, 296, 31, 320); }

The map function takes an input value to map (the day of the month), a from range (1 to the number of days in the month), and a to range (296 to 320 in your example). It returns a value in the to range based on where the input value is in the from range.

int min = map(day, 1, 31, 296, 320);

When day is 1, map will return 296. When day is 31, map will return 320. For other values of day, map will return a value between 296 and 320.

Rather than a series of if tests, though, to call the correct map function, use some arrays.

int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int minMinute[12] = {296, ...}; int maxMinute[12] = {320, ...};

Then, you just need one map statement:

int min = map(day, 1, daysInMonth[month-1], minMinute[month-1], maxMinute[month-1]);

Thanks for the help so far guys, things are starting to clear up a bit.

How would i go about makeing arrays with the following data?

int janStart        =          map(dayOfMonth, 1, 31, 296, 320);
int febStart        =          map(dayOfMonth, 1, 29, 321, 340);
int marStart        =          map(dayOfMonth, 1, 31, 340, 356);
int aprStart        =          map(dayOfMonth, 1, 30, 357, 372);
int mayStart        =          map(dayOfMonth, 1, 31, 372, 389);
int junStart        =          map(dayOfMonth, 1, 30, 389, 398);
int julStart        =          map(dayOfMonth, 1, 31, 398, 389);
int augStart        =          map(dayOfMonth, 1, 31, 389, 360);
int sepStart        =          map(dayOfMonth, 1, 30, 361, 328);
int octStart        =          map(dayOfMonth, 1, 31, 327, 298);
int novStart        =          map(dayOfMonth, 1, 30, 297, 285);
int decStart        =          map(dayOfMonth, 1, 31, 285, 296);

I need to be able to identify the month with data from the RTC;

int month

Thanks again guys

I need to be able to identify the month with data from the RTC;

You're kidding, right?

Sorry Paul,

I had a better look at the code you posted this morning and see where it calls for the month, was a bit tired yesterday just came off of night shift.

I put everything in and it works great.

Thanks for your help,

Jason