/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott http://people.interaction-ivrea.it/m.rinott
modified on 8 Nov 2013
by Scott Fitzgerald
*/
#include <Wire.h>
#include "ds3231.h"
#include <Servo.h>
int potpin = 0; // Analog pin is used to connect the potentiometer
int val; // Variable to read the value from the analog pin
int pause = 800; // Delay in open feeders (feed amount)
Servo myservo; // create servo object to control a servo
#define BUFF_MAX 256
// First Service
uint8_t wake_HOUR1 = 12;
uint8_t wake_MINUTE1 = 56;
uint8_t wake_SECOND1 = 0;
// Second Service
uint8_t wake_HOUR2 = 18;
uint8_t wake_MINUTE2 = 30;
// How often to update the information to the standard output (ms)
unsigned long prev = 5000, interval = 5000;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write (0); // Set the position to 0
Serial.begin (9600);
Wire.begin ();
DS3231_init (DS3231_INTCN);
DS3231_clear_a1f ();
DS3231_clear_a2f ();
set_alarm ();
}
void loop()
{
char buff [BUFF_MAX];
unsigned long now = millis ();
struct ts t;
// Output through time (5000ms) The time and alarm clocks ustanovlennnye
if ((now - prev> interval) && (Serial.available () <= 0)) {
DS3231_get (& t);
// Display current time
snprintf (buff, BUFF_MAX, ".% d% 02d% 02d% 02d:.% 02d:% 02d", t.year,
t.mon, t.mday, t.hour, t.min, t.sec);
Serial.println (buff);
// Display a1 debug info
DS3231_get_a1 (& buff [0], 59);
Serial.println (buff);
DS3231_get_a2 (& buff [0], 59);
Serial.println (buff);
if (DS3231_triggered_a1 ()) {
// INT has been pulled low
Serial.println ( "-> First Service load");
myservo.write(10); // sets the servo position according to the scaled value
delay(1000); // waits for the servo to get there
myservo.write(170); // sets the servo position according to the scaled value
delay(1000); // waits for the servo to get there
// Clear a1 alarm flag and let INT go into hi-z
DS3231_clear_a1f ();
}
if (DS3231_triggered_a2 ()) {
// INT has been pulled low
Serial.println ( "-> Second Service load");
myservo.write(10); // sets the servo position according to the scaled value
delay(1000); // waits for the servo to get there
myservo.write(170); // sets the servo position according to the scaled value
delay(1000);
}