# include <time.h>
struct tm firstTime;
struct tm todayTime;
time_t baseTime;
time_t codeTime;
void setup()
{
mySetup();
printf("\nhello world.\n");
test();
}
void loop()
{
}
int test()
{
printf("Hello World ");
/*
9/21/22 4067 0173
9/22/22 4239 0172
10/10/22 7349 0173
*/
int baseCode = 4239;
firstTime.tm_year = 2022 - 1900;
firstTime.tm_mon = 9 - 1; // 22 september 2022
firstTime.tm_mday = 22;
firstTime.tm_hour = 12;
firstTime.tm_min = 0;
firstTime.tm_sec = 1;
firstTime.tm_isdst = -1;
if (mktime(&firstTime) == -1)
printf("-unknown-");
baseTime = mktime(&firstTime);
todayTime.tm_year = 2022 - 1900;
todayTime.tm_mon = 10 - 1; // 10 october 2022
todayTime.tm_mday = 10;
todayTime.tm_hour = 12;
todayTime.tm_min = 0;
todayTime.tm_sec = 1;
todayTime.tm_isdst = -1;
if (mktime(&todayTime) == -1)
printf("-unknown-");
codeTime = mktime(&todayTime);
printf("%ld %ld %ld %ld\n", baseTime, codeTime, codeTime - baseTime, (codeTime - baseTime) / 86400L);
int daysSince = (codeTime - baseTime) / 86400L;
int roller = 0;
int newCode = baseCode;
for (int dd = 0; dd < daysSince; dd++) {
// add 173 three times and 172 once
if (roller < 3) newCode += 173;
else newCode += 172;
// poor man's modulo 10000
if (newCode >= 10000) newCode -= 10000;
roller++; roller &= 0x3;
}
printf("\n\n new code %d\n", newCode);
return 0;
}
# include <stdio.h>
int serial_putc(char c, FILE *)
{
Serial.write(c);
return c;
}
void printf_begin(void)
{
fdevopen(&serial_putc, 0);
}
void mySetup()
{
Serial.begin(115200);
printf_begin();
}