I am trying to get a sketch working where I can put in longitude, latitude, date and time and get back solar elevation and azimuth.
The following looks like it will do exactly that.
I can't get it to compile. I'm quite sure I don't have the right libraries, headers, or whatever in the right places.
I don't have a good understanding of what goes where. I know there is a folder arduino\libraries.
I tried doing a copy and paste into a file there but I don't know if that's right.
At this point, I'm trying to compile this sketch:
// solarTimeNoClockDemo
// Arduino example sketch for SolarPosition library
//
// Calculate solar position from time and location information
// not using any clock to keep time. Just do calculations.
// 2017 Ken Willmott
// Arduino library based on the program "Arduino Uno and Solar Position Calculations"
// (c) David R. Brooks, which can be found at http://www.instesre.org/ArduinoDocuments.htm
// and issued under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License:
// https://creativecommons.org/licenses/by-nc-nd/4.0/
#include <SolarPosition.h>
// number of decimal digits to print
const uint8_t digits = 3;
// some test positions:
SolarPosition Timbuktu(16.775214, -3.007455); // Timbuktu, Mali, Africa
// create a fixed UNIX time to test fixed time method
int someS = 0; //second
int someM = 0; //minute
int someH = 12; //hour
int someD = 15; //day
int someMo = 4; //month
int someY = 1985; //year
tmElements_t someTime = {someS, someM, someH, 0, someD, someMo, CalendarYrToTm(someY) };
time_t someEpochTime = makeTime(someTime);
// program begins
void setup()
{
Serial.begin(9600);
Serial.println(F("\tSolar Position Demo"));
// First test the fixed time methods:
//
Serial.print(F("The sun was at an elevation of "));
Serial.print(Timbuktu.getSolarElevation(someEpochTime), 4);
Serial.print(F(" and an azimuth of "));
Serial.println(Timbuktu.getSolarAzimuth(someEpochTime), 4);
Serial.print(F("in Timbuktu at "));
printTime(someEpochTime);
Serial.print(F("The earth was "));
Serial.print(Timbuktu.getSolarDistance(someEpochTime), 0);
Serial.println(F(" km from the Sun."));
Serial.println();
Serial.println(F("Done..."));
Serial.println();
}
void loop()
{
}
// Print a solar position to serial
//
void printSolarPosition(SolarPosition_t pos, int numDigits)
{
Serial.print(F("el: "));
Serial.print(pos.elevation, numDigits);
Serial.print(F(" deg\t"));
Serial.print(F("az: "));
Serial.print(pos.azimuth, numDigits);
Serial.println(F(" deg"));
}
// Print a time to serial
//
void printTime(time_t t)
{
tmElements_t someTime;
breakTime(t, someTime);
Serial.print(someTime.Hour);
Serial.print(F(":"));
Serial.print(someTime.Minute);
Serial.print(F(":"));
Serial.print(someTime.Second);
Serial.print(F(" UTC on "));
Serial.print(dayStr(someTime.Wday));
Serial.print(F(", "));
Serial.print(monthStr(someTime.Month));
Serial.print(F(" "));
Serial.print(someTime.Day);
Serial.print(F(", "));
Serial.println(tmYearToCalendar(someTime.Year));
}
I get this error message:
Arduino: 1.8.4 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\Ted\AppData\Local\Temp\ccGHZPKu.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_solarTimeNoClockDemo.ino.cpp.o.1895':
ccGHZPKu.ltrans0.o:(.text.startup+0xa8): undefined reference to `SolarPosition::SolarPosition(float, float)'
C:\Users\Ted\AppData\Local\Temp\ccGHZPKu.ltrans0.ltrans.o: In function `main':
ccGHZPKu.ltrans0.o:(.text.startup+0x2cc): undefined reference to `SolarPosition::getSolarElevation(unsigned long)'
ccGHZPKu.ltrans0.o:(.text.startup+0x2ee): undefined reference to `SolarPosition::getSolarAzimuth(unsigned long)'
ccGHZPKu.ltrans0.o:(.text.startup+0x526): undefined reference to `SolarPosition::getSolarDistance(unsigned long)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Can someone tell me what files I need and where I need to put them? That would be very much appreciated. I've been stumbling around trying stuff for hours and I just don't know what I'm doing.