This is what the IDE generates from your code before compiling it (your function not commented out):
#line 1 "sketch_mar29a.ino"
#define myBirthday 7
#define Christmas 5
#define NewYears 11
/*
struct dateTime {
byte month;
byte dayOfMonth;
int year;
};
dateTime curDT = {6,22,1963};
// The code above compiles IF I get rid of the isHoliday() function
// but gives error: 'dateTime' was not declared in this scope
// on line 8 with the isHoliday() function unremarked
/*
// These don't work, gives error: 'curDT' does not name a type
// so how do I get or alter a value from one of it's elements?
//curDT.Month = 8;
//curDT->month = 8;
*/
//Also tried it as a class, like this:
#include "Arduino.h"
void setup();
void loop();
int isHoliday(dateTime dt, int holidays[]);
boolean addHoliday(int holidays[], int &numHolidays, int newHoliday);
#line 26
class dateTime {
public:
byte month;
byte dayOfMonth;
int year;
dateTime();
};
dateTime::dateTime() {
this->month = 1;
this->dayOfMonth = 1;
this->year = 1970;
}
dateTime curDT();
/*
// These don't work with the class either, also gives error: 'curDT' does not name a type
// so how do I get or alter a value from one of it's elements?
//curDT.Month = 8;
//curDT->month = 8;
*/
int holidayList[] = { 0,0,0,0,0,0,0,0,0,0 }; // Maximum of 10 holidays or events on a single day
int holidayCount = 0;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
} // void setup
void loop()
{
// put your main code here, to run repeatedly:
int result;
//result = isHoliday(curDT, holidayList);
Serial.print ("Holiday Count = ");
Serial.println (holidayCount);
Serial.print ("Holidays: ");
for (int i=0; i<holidayCount; i++) {
Serial.print (holidayList[i]);
Serial.print (", ");
} // for holiday loop
} // void loop()
int isHoliday(dateTime dt, int holidays[])
// causes error: 'dateTime' was not declared in this scope
// on line 8 above with the isHoliday() function not remarked out
{
int numHolidays=0;
addHoliday(holidays, numHolidays, myBirthday);
addHoliday(holidays, numHolidays, Christmas);
return numHolidays;
} // int isHoliday
boolean addHoliday(int holidays[], int &numHolidays, int newHoliday)
{
if (numHolidays < 10) {
holidays[numHolidays] = newHoliday;
numHolidays++;
return true;
} // if (curCount < 10)
else {
return false;
} // else if (curCount < 10)
} // boolean addHoliday
You can avoid that if you separate your code and move the declaration of the dateTime class to a file "dateTime.h", the definition of the constructor to "dateTime.cpp" (where you include "dateTime.h") and put an include "dateTime.h" at the top of your main sketch.
You can also use the struct but remember that a struct is always called by its full name. So if you defined the struct as in the comments at the top of your code, you have to use it as "struct dateTime" and not just "dateTime".