Go Down

Topic: elapsed lib question [SOLVED] (Read 384 times) previous topic - next topic


Jan 23, 2012, 10:59 am Last Edit: Jan 23, 2012, 11:45 am by yair Reason: 1
using the elapsed lib from gammon,  basicly trying a chase sequence with no delays.

im having a problem with scope, i think.

here is the code, (should compile if you have the elapsed lib).
what im seeing is the first (nested?) timer function works ok with the specified intervals, the second one doesn't - much shorter.  
i included the output from the serial in the code.

EDIT: i think i found the bug, seems i need to reset the next timer in the sequence before calling it (duh). added  time[pin+1].reset();
Code: [Select]

#include <Elapsed.h> //http://www.gammon.com.au/forum/?id=11094

static Elapsed time [3]; //an array of two timers (would be 24 in real code)
int Hstate[3]={99,99,99};  //mini state machine for inside the timer function H_pulseWave

// just some pins configured...
int hepticPin[2][3] = {
  {1,5,6},//[ number, pinFWD, pinBWD]

int intrvl_kick = 1000;
int intrvlOFF = 50;
int intrvlON = 100;

void setup(){
  Serial.begin(19200);  // initialize serial communication:

void loop(){

here is (was :))  the strange bit, the first H_pulseWave  will output the correct intervals , the second, much shorter pulses.
1 1001
1 1051
1 1151

2 1155
2 1159
2 1164

void H_pulseWave(int pin){
  if(time[pin].intervalMs() > intrvl_kick && Hstate[pin]==0)
    Serial.print(pin);     Serial.print(" ");     Serial.println(time[pin].intervalMs() ); 
  if(time[pin].intervalMs() > intrvl_kick+intrvlOFF && Hstate[pin]==1) //50
    Serial.print(pin);        Serial.print(" ");      Serial.println(time[pin].intervalMs() ); 

  if(time[pin].intervalMs() > intrvl_kick+intrvlOFF+intrvlON && Hstate[pin]==2) //15
    Serial.print(pin);      Serial.print(" ");     Serial.println(time[pin].intervalMs() ); 
    Hstate[pin]=99; // make this offline , will check this on the main loop
    Hstate[pin+1]=0; // triger next one pin in wave loop
    time[pin+1].reset(); //added this! to fix bug


void H_bwd(int pin){
  digitalWrite(hepticPin[pin][1], LOW);   
void H_fwd(int pin){
  digitalWrite(hepticPin[pin][1], HIGH);   

void H_off(int pin){
  digitalWrite(hepticPin[pin][1], LOW);   

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131