What are useful tips on saving time(min, sec) to pass to next function last, using Stop and Pause from within function using the code below..........?
Would like to:
- turn on relay1 3 times.
- turn off relay1
- turn on relay2 latch and start timer for say 5min.
- After 5min. stop timer and turn off relay2
- return to step one.
repeat this loop three times at 0min, 5min, 10min and end at 20min.
#include "Countimer.h"
#include <genieArduino.h>
Genie genie;
Countimer timer;
#define Relay1Pin 5
#define Relay2Pin 6
int Relay1,Relay2;
int mySecond;
int myMinute;
void setup() {
Serial.begin(9600);
genie.Begin(Serial);
genie.AttachEventHandler(myGenieEventHandler);
delay (5000);
genie.WriteContrast(15);
digitalWrite (Relay1Pin, HIGH);
digitalWrite (Relay2Pin, HIGH);
pinMode (Relay1Pin, OUTPUT);
pinMode (Relay2Pin, OUTPUT);
// Set up count down timer with 10s and call method onComplete() when timer is complete.
// 00h:00m:10s
// timer.setCounter(0, 0, 5, timer.COUNT_UP, onComplete);
// Print current time every 1s on serial port by calling method refreshClock().
timer.setInterval(refreshClock, 1000);
}
void loop() {
genie.DoEvents();
timer.run(); // Run timer
//if(!timer.isCounterCompleted()) {
// timer.start();
}
void StepOne(){
for(int i=0; i<3; i++)
{
digitalWrite (Relay1Pin, LOW);
delay(500);
digitalWrite (Relay1Pin, HIGH);
delay(500);
}
timer.setCounter(0, 0, 6, timer.COUNT_UP,StepTwo);
digitalWrite (Relay2Pin, LOW);
timer.start();
}
void StepTwo(){
timer.pause();
digitalWrite (Relay2Pin,HIGH);
for(int i=0; i<3; i++)
{
digitalWrite (Relay1Pin, LOW);
delay(500);
digitalWrite (Relay1Pin, HIGH);
delay(500);
}
timer.setCounter(0, 0, 11, timer.COUNT_UP,StepThree);
digitalWrite (Relay2Pin, LOW);
timer.start();
}
void StepThree(){
timer.pause();
digitalWrite (Relay2Pin, HIGH);
for(int i=0; i<3; i++)
{
digitalWrite (Relay1Pin, LOW);
delay(500);
digitalWrite (Relay1Pin, HIGH);
delay(500);
}
timer.setCounter(0, 0, 20, timer.COUNT_UP,onComplete);
digitalWrite (Relay2Pin, LOW);
timer.start();
}
void refreshClock() {
mySecond = timer.getCurrentSeconds();
myMinute = timer.getCurrentMinutes();
genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, myMinute);
genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, mySecond);
}
void onComplete() {
String Str = "Complete!!!";
genie.WriteStr(0,Str);
digitalWrite (Relay2Pin, HIGH);
// timer.stop();
}
void myGenieEventHandler()
{
genieFrame Event;
genie.DequeueEvent (&Event);
if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
{
if (Event.reportObject.object == GENIE_OBJ_WINBUTTON)
{
if (Event.reportObject.index == 3)
{
StepOne();
}
if (Event.reportObject.index == 4)
{
timer.pause();//var2 = genie.GetEventData (&Event);
}
if (Event.reportObject.index == 6)
{
timer.stop();//var3 = genie.GetEventData (&Event);
}
}
}
}