Good afternoon, I am creating an automatic animal feeder. I already connected everything and wrote the code, but I got an error "was not declared in this scope" in line 36 ("DS1302_set_a1 (wake_SECOND1, wake_MINUTE1, wake_HOUR1, 0, flags1);")
This is how the error sounds completely: "exit status 1
'DS1302_set_a1' was not declared in this scope "
I re-read the code and cannot find the cause of the error. Maybe someone's new look will help me.
Immediately apologize for my English.
Thanks in advance.
#include <Wire.h>
#include <DS1302.h>
#include <Servo.h>
Servo myservo; // create a servo object to control the servo
int potpin = 0; // analog pin is used to connect a potentiometer
int val; // variable to read values from analog pin
int pause = 800; // open time delay (amount of feed)
#define BUFF_MAX 256
// First alarm
uint8_t wake_HOUR1 = 9;
uint8_t wake_MINUTE1 = 42;
uint8_t wake_SECOND1 = 0;
// Second alarm
uint8_t wake_HOUR2 = 18;
uint8_t wake_MINUTE2 = 30;
// how often to update information on standard output (ms)
unsigned long prev = 5000, interval = 5000;
void set_alarm(void)
{
// flags determine which component of the calendar will be checked at the current time in the order
// to trigger an alarm - see data table
// A1M1 (seconds) (0 to enable, 1 to disable)
// A1M2 (minutes) (0 to enable, 1 to disable)
// A1M3 (hour) (0 to enable, 1 to disable)
// A1M4 (day) (0 to enable, 1 to disable)
// DY / DT (dayofweek == 1 / dayofmonth == 0)
uint8_t flags1[5] = { 0, 0, 0, 1, 1 }; // Flag for the first alarm clock (every day)
uint8_t flags2 [4] = {0, 0, 1, 1}; // In the second alarm clock, seconds are not counted (as it is written in the library)
// set our alarm values from variables (for the first)
DS1302_set_a1 (wake_SECOND1, wake_MINUTE1, wake_HOUR1, 0, flags1);
// set our alarm values from variables (for the second - without seconds)
DS1302_set_a2 (wake_MINUTE2, wake_HOUR2, 0, flags2);
// Activate the first alarm
DS1302_set_creg (DS1302_INTCN | DS1302_A1IE);
// Activate the second alarm
DS1302_set_creg (DS1302_INTCN | DS1302_A2IE);
}
This is a snippet of code (it’s just big, but if necessary I can completely throw it off)
spycatcher2k,
Maybe I just don’t understand something, but now I get an error: "exit status 1
'DS1302_set_a1' cannot be used as a function "on the same line.
It may be better if I throw off all the code.
#include <Wire.h>
#include <DS1302.h>
#include <Servo.h>
Servo myservo; // create a servo object to control the servo
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 state of the feeder (amount of feed)
#define BUFF_MAX 256
// First alarm
uint8_t wake_HOUR1 = 9;
uint8_t wake_MINUTE1 = 42;
uint8_t wake_SECOND1 = 0;
// Second alarm
uint8_t wake_HOUR2 = 18;
uint8_t wake_MINUTE2 = 30;
// how often to update information to standard output (ms)
unsigned long prev = 5000, interval = 5000;
void set_alarm (void)
{
uint8_t flags1 [5] = {0, 0, 0, 1, 1}; // Flag for the first alarm clock (every day)
uint8_t flags2 [4] = {0, 0, 1, 1}; // In the second alarm clock, seconds are not counted (as it is written in the library)
int DS1302_set_a1 = 0;
int DS1302_set_a2 = 0;
// set our alarm values from variables (for the first)
DS1302_set_a1 (wake_SECOND1, wake_MINUTE1, wake_HOUR1, 0, flags1);
// set our alarm values from variables (for the second - without seconds)
DS1302_set_a2 (wake_MINUTE2, wake_HOUR2, 0, flags2);
// Activate the first alarm
DS1302_set_creg (DS1302_INTCN | DS1302_A1IE);
// Activate the second alarm
DS1302_set_creg (DS1302_INTCN | DS1302_A2IE);
}
void setup ()
{
myservo.attach (14); // Servo output to A0 (14 pin)
myservo.write (0); // Set Position To 0
Serial.begin (9600);
Wire.begin ();
DS1302_init (DS1302_INTCN);
DS1302_clear_a1f ();
DS1302_clear_a2f ();
set_alarm ();
}
void loop ()
{
char buff [BUFF_MAX];
unsigned long now = millis ();
struct ts t;
// Display the time and set alarms after a period of time (5000ms)
if ((now - prev> interval) && (Serial.available () <= 0))
{
DS1302_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
DS1302_get_a1 (& buff [0], 59);
Serial.println (buff);
DS1302_get_a2 (& buff [0], 59);
Serial.println (buff);
if (DS1302_triggered_a1 ())
{
// INT has been pulled low
Serial.println ("-> The first alarm went off");
myservo.write (120); // sets the position of the servo to the open position (in my case, 120 degrees.)
delay (pause);
myservo.write (0);
// clear a1 alarm flag and let INT go into hi-z
DS1302_clear_a1f ();
}
if (DS1302_triggered_a2 ())
{
// INT has been pulled low
Serial.println ("-> Second alarm worked");
myservo.write (120); // sets the position of the servo to the open position (in my case, 120 degrees.)
delay (pause);
myservo.write (0);
// clear a1 alarm flag and let INT go into hi-z
DS1302_clear_a2f ();
}
prev = now;
}
}