Help repair

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:

  1. turn on relay1 3 times.
  2. turn off relay1
  3. turn on relay2 latch and start timer for say 5min.
  4. After 5min. stop timer and turn off relay2
  5. 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);      
          }
      }

    }
}

What are useful tips on saving time or passing last time from each function or what improved logic that will with below..........? It works but not anything like I as thought out because program skills.

Would you please rephrase your question?

Maybe instead of using Countimer.h I should use Timer library with alarms? :o

thevault:
Maybe instead of using Countimer.h I should use Timer library with alarms? :o

Why are you even using a timer library at all? Why not just use millis() (eg, blinkwithoutdelay style)?

This is just a piece of a program that I'm working on and would like to stick around the Countimer.h library. :o

thevault:
This is just a piece of a program that I'm working on and would like to stick around the Countimer.h library. :o

OK, if you want to do it the hard way be our guest. Nobody can stop you. But expecting us to help you with a library none of us know about without providing links to it is a bit unrealistic especially when there are much easier ways to accomplish what you want.

The library is similar to the CountUpDownTimer on this site which is buggy.....but here's the "Countimer" library. Are libraries frown upon within this group?

Countimer-master.zip (4.29 KB)

thevault:
Are libraries frown upon within this group?

I think libraries that make simple things more complicated would be frowned upon anywhere. A library should make things easier, not harder to understand.

Delta_G:
I think libraries that make simple things more complicated would be frowned upon anywhere. A library should make things easier, not harder to understand.

The effective complexity of a tool varies with the scale of the task. "Helper" libraries can be useful for simplifying complex tasks, but can definitely be overkill for simple tasks. On the other hand, tasks which appear simple on a small scale, often present difficulties when the scale is expanded to handle more data or more complex situations.

Wisdom is knowing when to switch from one to the other. Not leaving it until it is too late, so you have to "drain the swamp when you are up to your neck in alligators".

I guess I'm better off scanning sites and figuring it out for myself since all I get here is.......... :confused:

thevault:
I guess I'm better off scanning sites and figuring it out for myself since all I get here is.......... :confused:

Sure. It's what I do. I think it's just that nobody knows. But overall, there is a relatively high solution rate on this forum. Especially considering that nobody gets paid for helping.

thevault:
I guess I'm better off scanning sites and figuring it out for myself since all I get here is.......... :confused:

Sounds like a plan.

You were given good advice, but failed to heed it.

And perhaps if you'd given a link to the library's documentation, instead of just attaching the library, someone might have been encouraged to take a look.
It's unlikely that anyone's going to download and install the library just to test your code and tell you where you're going wrong, especially since it's so easy to achieve what you want using 'millis()'-based timing.

Why the heck are you so dead-set against using 'millis()'?

And despite the fact that you said this:- "This is just a piece of a program that I'm working on and would like to stick around the Countimer.h library.", in the previous post you said "Maybe instead of using Countimer.h I should use Timer library with alarms?", so you're obviously open to using a different method.

Have you even considered using 'millis()', or is it just that you don't want to learn to do things properly?

The usual way to do this is with a variable to track state and with milis.

boolean doingRelay1;
int relay1Count;
boolean relay1High;
unsigned long mark_ms;

// output pins
const byte R1 = 5;
const byte R2 = 6;

// duration settings
const unsigned long r1_high_ms = 250;
const unsigned long r1_low_ms = 250;
const unsigned long r2_high_ms = 5L * 60L * 1000L;

void setup() {
  // we set this up so the main loop thinks we have just finished doing relay 2

  doingRelay1 = false;
  mark_ms = -r2_high_ms;
}



void loop() {
  // put your main code here, to run repeatedly:

  unsigned long ms = millis();
  unsigned long duration = ms - mark_ms;

  if (doingRelay1) {
    if (relay1High) {
      if (duration >= r1_high_ms) {
        digitalWrite(R1, LOW);
        if (relay1Count == 3) {
          doingRelay1 = false;
          digitalWrite(R2, HIGH);
          mark_ms = ms;
        }
        else {
          relay1High = false;
          mark_ms = ms;
        }
      }
      // else leave r1 high for now
    }
    else {
      if (duration >= r1_low_ms) {
        digitalWrite(R1, HIGH);
        relay1High = true;
        mark_ms = ms;
        relay1Count++;
      }
      // else leave r2 low for now
    }
  }
  else {
    if (duration >= r2_high_ms) {
      digitalWrite(R2, LOW);
      doingRelay1 = true;
      relay1High = false;
      relay1Count = 0;
      // trick the other branch into going high immediately
      mark_ms = -r1_low_ms;
    }
    // else leave r2 high for now
  }
}