Timer required

Hi,
I made some projects and finally need some help. Ok, I had a lot of help reading here but never asked a question.

My problem is following: I've build a controller for my automatic blinds. I implemented functions for up, down and stop. basically, there are relays where I trigger the corresponding digital out pin.

I wanted to have a 4th option implemented to drive it only for X seconds (eg. full is 50, so stop after 25).
Of course this works with the delay(25000) however I do not like that as it blocks the whole program and in case I want to stop it in between, it cannot be achieved by any manual inputs.

I experimented with the various timer functions (Simple Timer, Timer etc) but none of them seems to work or I just didn't use them correct.

When looking at Arduino Playground - Timer Library
there is function pulse() which should do exactly what I am looking for.

In my simple code, I am looping through the 4 cases and set the pins 9 & 10 to high and low and if the timer would work, then in case "middle" pin 9 should set to high (which it does) and turn back to low after 2 seconds (which it doesn't). Only after the next case kicks in, it is set correct again.

What am I missing here?

Any comment highly welcome!
thanks,
SJ

#include "Timer.h"
#include <SoftwareSerial.h>
Timer t;

String inputComand = "middle";

void setup() {
  Serial.begin(19200);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  t.pulse(9, 2000, LOW); //this should change pin 9 for 2 sec from LOW to HIGH)
}

void loop() {
for (int i = 0; i<=3; i++){
  simulationComand(i);
if (inputComand == "up"){
  Serial.println("CASE up");
  driveUp();
}
else if (inputComand =="down"){
  Serial.println("CASE down");
  driveDown();
}
else if (inputComand =="middle"){
  Serial.println("CASE middle");
  Serial.println("------Start timer");
 t.update();
 Serial.println("------timer runs");
  //driveMiddle();
}
else{
  Serial.println("CASE stop");
  stopp();
}
Serial.println("WAIT 6 sec");
delay(6000);
}
}

void driveUp(){
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  return;
 }

 void driveDown(){
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  return;
 }

  void stopp(){
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  return;
 }

  void driveMiddle(){
  Serial.println("----------");
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  delay(5000);
  digitalWrite(10, LOW);
  Serial.println("----------");
  return;
 }


 void simulationComand(int counter){
    if (counter == 0){
      inputComand ="up";
      Serial.println("changed to up");}
    else if (counter == 1){
      inputComand ="down";
      Serial.println("changed to down");}
    else if (counter == 2){
      inputComand ="stop";
      Serial.println("changed to stop");}
    else{
      inputComand ="middle";
      Serial.println("changed to middle");}
 }

Use the blink without delay paradigm. Start your blinds moving and then on each pass of the loop function see if it is time to stop them.

Thank you Delta_G. However I only get it to blink once. How do I reset it?
during startup it is setting the pin to high once and then is it not accessible. This should be triggered by an input anytime.

Cheers,
SJ

Then you did something wrong :smiley: Show your new code and we can figure out what you did wrong.

obviously I did.
In reality my code is quite different from the example here, I left all the UDP handling etc. out.
I gave Metro a shot and that worked as expected after 15min or so.

Thank you anyway for the help.

SJ