In this sketch I need to add a command ,so I can stop TimeAlarm triger spinning() every time i reset timer (or I add hours with a seccond button).
I need spinning triggered 60 sec after turn on or reset and after that ,every hour.
thank you
#include <Time.h>
#include <TimeAlarms.h>
#include <Stepper.h>
int MYType;
int resetPin = A2;
int addHourPin = A3;
int addMinPin = A4;
const int stepsPerRevolution = 48;
Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);
void setup(){
stepper.setSpeed(150);
setTime(0,0,0,1,1,11);
Alarm.timerOnce(60, spinning); //step motor spins 60 sec after boot
Alarm.timerRepeat(3600, spinning); //step motor spins after an hour
}
void loop(){
// RANDOM COMMANDS
/*=========== GENERAL reset pin. Everithing resets to zero when presed=============*/
if(digitalRead(resetPin) == HIGH){
Resetingeverithing ();
//command to turn off Alarm.timers
setTime(0,0,0,1,1,11); //at this point Alarms are trigered always
//command to turn on Alarm.timers
}//end of reset
} //END of LOOP
void Resetingeverithing () {
Alarm.delay (2000);
lcd.clear();
lcd.print("timer will be set back to zero");
//going back to loop
}
void spinning (){
stepper.step(100);
}
I am not clear what you want to do exactly, and your current code does nothing as far as I can see, apart from constantly setting the time to the same values every time through loop(). The alarms will not trigger because you have no call to Alarm.delay() in loop() and even your Resetingeverithing() function does nothing but wait 2 seconds, clear the LCD and then print a message.
If you want to turn alarms on and off you need to know their ID, which you get like this
ID = Alarm.timerOnce(60, spinning);
Then, to disable/enable an alarm do this
disable(ID); //- prevent the alarm associated with the given ID from triggering
enable(ID); // - enable the alarm
my code is redused to minimal so you can understand what I need.
so my code needs to be like this ?
#include <Time.h>
#include <TimeAlarms.h>
#include <Stepper.h>
int MYType;
int resetPin = A2;
int addHourPin = A3;
int addMinPin = A4;
int ID ;
int ID2 ;
const int stepsPerRevolution = 48;
Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);
void setup(){
stepper.setSpeed(150);
setTime(0,0,0,1,1,11);
ID = Alarm.timerOnce(60, spinning);
ID2=Alarm.timerRepeat(3600, spinning);
// Alarm.timerOnce(60, spinning); //step motor spins 60 sec after boot
// Alarm.timerRepeat(3600, spinning); //step motor spins after an hour
}
void loop(){
RANDOM COMMANDS ;
/*=========== GENERAL reset pin. Everithing resets to zero when presed=============*/
if(digitalRead(resetPin) == HIGH){
Resetingeverithing ();
//command to turn off Alarm.timers
disable(ID);
disable(ID2);
setTime(0,0,0,1,1,11); //at this point Alarms are trigered always
//command to turn on Alarm.timers
enable(ID);
enable(ID2);
}//end of reset
} //END of LOOP
void Resetingeverithing () {
Alarm.delay (2000);
lcd.clear();
lcd.print("timer will be set back to zero");
//going back to loop
}
void spinning (){
stepper.step(100);
}
because it gives me this
sketch_feb21a:41: error: 'disable' was not declared in this scope
sketch_feb21a:45: error: 'enable' was not declared in this scope
enable and disable are functions of TimeAlarms so they need to be identified as such like any other functions in the library. Call them like this.
Alarm.disable(ID);
I am still not sure what your code tries to do, partly because it is not formatted. Please use Tools/Auto Format from the IDE menu.
Why do you set the current time over and over in loop() ?
What may be happening is that when you set the current time in loop() it is in the past so the alarm conditions are met immediately, but I am not sure.
Thank you for your awsers .
As I told you before I chopped my originally sketch so it is more easy to understand my problem
Originally this sketch is an egg incubbator and timer needed for egg spinning