Okay,…maybe I played a little more, I was multitasking on wedding things as well. I have nearly finished the prototype with the current and tested iteration of the sketch on it, still waiting to test the servo operation values.
I have also been fiddling around with the time libraries guide, and time.alarm. I think this (see below) is close to the DS1307 program that I would need to use. I think this will also write the time to the serial monitor. I don’t have a board to test this on at the moment as mine is currently in service, I have more on the way though.
Hopefully this will use option two;
However not store the feed data, so if it’s interrupted it could cause an issue with the written time. If I removed the time write line on this sketch, as the DS1307 has time stamped onto it already, would it just use the alarm time to go off? Something I can test and play around with once I have another board.
I have also added some more possible development ideas at the bottom of the code, so I can move them up as I add code and complication.
Thanks,
Cup
/*
* This is a code structure for my Cat feeder.
* It needs to get a servo motor to move every 12 hours, or at 0700 and 1900 using a DS1307
* with a long term reasonable degree of accuracy.
* Compiled from online resources and learning. For Cat feeder
* P Hoskins, Canberra, ACT, 04.10.16
* with help from littlebird forum -
* Secondary addition of an RTC controlled timer to the system
*/
// will require batteries- FUTURE solar and rechargeable system-
//these are the time library inclusions
#include <TimeLib.h>
#include <TimeAlarms.h>
AlarmId id;
// servo library inclusions
#include <Servo.h> //Adds servo library to system
Servo myservo; // names the servo, could also be a number??
const int servoPin = 11; //identifies servo pin
void setup() {
//Time and alarm codes
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
// Is this needed if I use the pre stamped time on the DS1307??
setTime(8,29,0,1,1,11); // set time at time of upload, use H,M,S DD,MM,YY
// create the alarms, to trigger at specific times
Alarm.alarmRepeat(7,00,0, MorningAlarm); // 7:00am every day
Alarm.alarmRepeat(19,00,0,EveningAlarm); // 7:00pm every day
// servo setup
pinMode(13, OUTPUT);
digitalWrite(13, 1);
myservo.attach(servoPin);
myservo.write(180);
delay(1000);
myservo.detach();
digitalWrite(13, 0);
}
void loop() {
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}
// functions to be called when an alarm triggers:
void MorningAlarm() {
Serial.println("Alarm: - Feedimng time"); //writes to LCD screem??
myservo.attach(servoPin);
myservo.write(90);
delay(1000); //open speed of the servo
myservo.write(180); //angle is changeable depending on the amount of food delivered
delay(1000); //close speed of the servo
myservo.detach();
}
void EveningAlarm() {
Serial.println("Alarm: - Feedimng time"); //writes to LCD screem??
myservo.attach(servoPin);
myservo.write(90);
delay(1000); //open speed of the servo
myservo.write(180); //angle is changeable depending on the amount of food delivered
delay(1000); //close speed of the servo
myservo.detach();
}
void digitalClockDisplay() {
// digital clock display of the time in serial monitor- FUTURE send to 2x16 LCD and scroll next feed //time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}
/*
* Further developments
* print time to a 2x16 lcd screen scrolling with not feed time and current time and count down??
* save last feed time incase of interuptions
* add solar charger to battery pack
* IoT extension for remote feeding
* camera, or a system to check cats are happy and eating.
* Low level food light, ambient light sensor in food hopper
*/