Double HIGH (with pause) and hold HIGH on output pin using Chrono library


hi everyone.

i'm trying make program (using chrono library) following:

1. when "input" high start counting (start chrono) , set "pin" high
2. when 200ms has passed set "pin" low
3. when 300ms has passed set "pin" high , hold in high long "input" high
4. if "input" low, set "pin" low

with code i've written "pin" high when "input" high.
and can't use "start()" command library, i've used restart (when use "mychrono.start();" error message while compiling " 'class chrono' has no member named 'start' "
any advice?

code: [select]
#include <chrono.h>


chrono mychrono;


int pin = 2;
int input = a2;


void setup() {
 
  pinmode (pin, output);
  pinmode (input, input);

}



void loop() {
  if (digitalread(input) == high) {

    digitalwrite(pin, high);

    mychrono.start();

    if (mychrono.haspassed(200)) {
      digitalwrite(pin, low);
      mychrono.restart();
    }

    if (mychrono.haspassed(300)) {
      digitalwrite(pin, high);
      mychrono.stop();
    }


  }


  else if (digitalread(input) == low) {
    digitalwrite(pin, low);
  }

}

code: [select]
void loop() {
  if (digitalread(input) == high) {

    digitalwrite(pin, high);

    mychrono.start();

the loop() function repeats thousands of times second input high time switch closed, assuming have wired go high when pressed , held low when not pressed.  if start method existed , worked, want or want start timer when input becomes high ?

personally use millis() timing , state machine control timing , actions , not use library.


Arduino Forum > Using Arduino > Programming Questions > Double HIGH (with pause) and hold HIGH on output pin using Chrono library


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading