#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <SunPosition.h>
#include <math.h>
// Initialize the motor shield
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *azimuthMotor = AFMS.getStepper(200, 2); // 200 steps/rev, motor port #2
Adafruit_StepperMotor *elevationMotor = AFMS.getStepper(200, 1); // 200 steps/rev, motor port #1
// Set up the GPS module
#define GPS_SERIAL Serial1
#define GPS_BAUD 9600
// Set up the real-time clock module
#define RTC_SDA 20
#define RTC_SCL 21
#include <DS3231.h>
DS3231 rtc(RTC_SDA, RTC_SCL);
void setup() {
// Set up the motor shield
AFMS.begin();
// Set up the GPS module
GPS_SERIAL.begin(GPS_BAUD);
// Set up the real-time clock module
rtc.begin();
}
void loop() {
// Get the current GPS location
float latitude = 0.0;
float longitude = 0.0;
if (GPS_SERIAL.available() > 0) {
if (GPS_SERIAL.find("$GPGGA")) {
// Parse the GPS message to get the latitude and longitude
latitude = GPS_SERIAL.parseFloat();
char latDirection = GPS_SERIAL.read();
longitude = GPS_SERIAL.parseFloat();
char lonDirection = GPS_SERIAL.read();
}
}
// Get the current time from the real-time clock
DateTime now = rtc.now();
int year = now.year();
int month = now.month();
int day = now.day();
int hour = now.hour();
int minute = now.minute();
int second = now.second();
// Calculate the sun position
SunPosition sunpos = SunPosition::calculate(year, month, day, hour, minute, second, latitude, longitude);
float altitude = sunpos.altitude * RAD_TO_DEG;
float azimuth = sunpos.azimuth * RAD_TO_DEG;
// Set the motor positions based on the sun position
int azimuthSteps = azimuth / 360.0 * 200.0 * 8.0; // Convert from degrees to steps, assuming 8x microstepping
int elevationSteps = altitude / 360.0 * 200.0 * 8.0; // Convert from degrees to steps, assuming 8x microstepping
azimuthMotor->step(azimuthSteps, FORWARD, MICROSTEP);
elevationMotor->step(elevationSteps, FORWARD, MICROSTEP);
// Wait for the next loop iteration
delay(1000);
}
I have got this code for heliostats control using solar position library and RTC
But it gets error "Adafruit_MotorShield()' could not be found.
Pls help i have checked this has already been added.
Pls check the code and current my code.