AndrewMascolo / CountUpDownTimer

MIT License
28 stars 20 forks source link

Timer starts even though the StartTimer method isnt called #2

Open PingPongLee opened 9 years ago

PingPongLee commented 9 years ago

I really like this library but im having some trouble with it. I want a timer to start at a specific point in my program. However when i reach this point its like the timer has been on for some time. I presume i have to activate the timer at this point by calling the method "StartTimer" and then call the Timer function each time i want it to "tick". But this does not work as intended I can show you some example code if desired

AndrewMascolo commented 9 years ago

Sure, show me your code.

Sent from my iPhone

On May 23, 2015, at 3:03 PM, PingPongLee notifications@github.com wrote:

I really like this library but im having some trouble with it. I want a timer to start at a specific point in my program. However when i reach this point its like the timer has been on for some time. I presume i have to activate the timer at this point by calling the method "StartTimer" and then call the Timer function each time i want it to "tick". But this does not work as intended I can show you some example code if desired

— Reply to this email directly or view it on GitHub.

PingPongLee commented 9 years ago
#include "CountUpDownTimer.h"
#include <Keypad.h>

CountUpDownTimer T(DOWN);

const byte rows = 4; 
const byte cols = 3;
char keys[rows][cols] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};
byte rowPins[rows] = {3, 2, 1, 0};
byte colPins[cols] = {6, 5, 4};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
char enter = '#';
char star = '*';

bool tmpBool=false;
bool oneTimer=false;

void setup()
{
    Serial.begin(115200);
    T.SetTimer(0,1,0);
}

void loop()
{
    if(keypad.getKey()==enter || tmpBool==true){
        tmpBool=true;   
        if(oneTimer==false){
            T.StartTimer();
            oneTimer=true;
        }
        T.Timer();
        if (T.TimeHasChanged() )
        {
            Serial.print(T.ShowHours());
            Serial.print(":");
            Serial.print(T.ShowMinutes());
            Serial.print(":");
            Serial.print(T.ShowSeconds());
            Serial.print(":");
            Serial.print(T.ShowMilliSeconds());
            Serial.print(":");
            Serial.println(T.ShowMicroSeconds());
        }   
    }
}

As you can probably tell i have a keypad i want to use. If i upload this to an arduino and dont press the enter key the timer will still count. Once i press the enter key it will output all the seconds that has passed from when the arduino booted till i pressed the button. Am i doing something completely wrong?

AndrewMascolo commented 9 years ago

I can’t help but notice the pins you are using. Are you using the digital pins 1 and 0 or the analog pins 1 and 0? If you are using the digital pins 1 and 0 then you should not be using the serial monitor and it too uses pins 1 and 0. Try to maybe shift your pins down and start from pin 2, and see if that helps.

From: PingPongLee [mailto:notifications@github.com] Sent: Saturday, May 23, 2015 3:52 PM To: AndrewMascolo/CountUpDownTimer Cc: AndrewMascolo Subject: Re: [CountUpDownTimer] Timer starts even though the StartTimer method isnt called (#2)

include "CountUpDownTimer.h"

include

CountUpDownTimer T(DOWN);

const byte rows = 4; const byte cols = 3; char keys[rows][cols] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'','0','#'} }; byte rowPins[rows] = {3, 2, 1, 0}; byte colPins[cols] = {6, 5, 4}; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols ); char enter = '#'; char star = '';

bool tmpBool=false; bool oneTimer=false;

void setup() { Serial.begin(115200); T.SetTimer(0,1,0); }

void loop() { if(keypad.getKey()==enter || tmpBool==true){ tmpBool=true;
if(oneTimer==false){ T.StartTimer(); oneTimer=true; } T.Timer(); if (T.TimeHasChanged() ) { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.print(T.ShowSeconds()); Serial.print(":"); Serial.print(T.ShowMilliSeconds()); Serial.print(":"); Serial.println(T.ShowMicroSeconds()); }
} }

As you can probably tell i have a keypad i want to use. If i upload this to an arduino and dont press the enter key the timer will still count. Once i press the enter key it will output all the seconds that has passed from when the arduino booted till i pressed the button. Am i doing something completely wrong?

— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/2#issuecomment-104939564 . https://github.com/notifications/beacon/AIon3r8z6tlhUn1zwFmtBb0uDah5bWNwks5oMNHSgaJpZM4EmoWP.gif

PingPongLee commented 9 years ago

Alright i decided to just take everything off of my arduino board and only attach a simple button ..

First i upload my code with the timer set to 1 minute in the setup method. I then wait 10 seconds after the arduino is booted.. When i then press the button the serial outputs the last 10 seconds at once, like the timer had been on from the start, even though my code shows that the button is supposed to enable and start the timer..

#include "CountUpDownTimer.h"

CountUpDownTimer T(DOWN);

const int buttonPin = 2;     
const int ledPin =  13;      
int buttonState = 0;       

bool tmpBool=false;
bool oneTimer=false;

void setup() {
    pinMode(ledPin, OUTPUT);      
    pinMode(buttonPin, INPUT);     
    Serial.begin(115200);
    T.SetTimer(0,1,0);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if(buttonState==HIGH || tmpBool==true)
  {       
    digitalWrite(ledPin, HIGH);  
    tmpBool=true;
    if(oneTimer==false)
    {
        T.StartTimer();
        oneTimer=true;
    }
    T.Timer();
    if (T.TimeHasChanged() )
    {
        Serial.print(T.ShowHours());
        Serial.print(":");
        Serial.print(T.ShowMinutes());
        Serial.print(":");
        Serial.print(T.ShowSeconds());
        Serial.print(":");
        Serial.print(T.ShowMilliSeconds());
        Serial.print(":");
        Serial.println(T.ShowMicroSeconds());
    }
  } 
  else 
  {
    digitalWrite(ledPin, LOW); 
  }
}
AndrewMascolo commented 9 years ago

Does your button have a pull-up resistor?

Sent from my iPhone

On May 23, 2015, at 4:46 PM, PingPongLee notifications@github.com wrote:

Alright i decided to just take everything off of my arduino board and only attach a simple button ..

First i upload my code with the timer set to 1 minute in the setup method. I then wait 10 seconds after the arduino is booted.. When i then press the button the serial outputs the last 10 seconds at once, like the timer had been on from the start, even though my code shows that the button is supposed to enable and start the timer..

include "CountUpDownTimer.h"

CountUpDownTimer T(DOWN);

const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;

bool tmpBool=false; bool oneTimer=false;

void setup() { pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(115200); T.SetTimer(0,1,0); }

void loop() { buttonState = digitalRead(buttonPin); if(buttonState==HIGH || tmpBool==true) {
digitalWrite(ledPin, HIGH);
tmpBool=true; if(oneTimer==false) { T.StartTimer(); oneTimer=true; } T.Timer(); if (T.TimeHasChanged() ) { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.print(T.ShowSeconds()); Serial.print(":"); Serial.print(T.ShowMilliSeconds()); Serial.print(":"); Serial.println(T.ShowMicroSeconds()); } } else { digitalWrite(ledPin, LOW); } } — Reply to this email directly or view it on GitHub.

AndrewMascolo commented 9 years ago

Correction, pull down resistor

Sent from my iPhone

On May 23, 2015, at 4:46 PM, PingPongLee notifications@github.com wrote:

Alright i decided to just take everything off of my arduino board and only attach a simple button ..

First i upload my code with the timer set to 1 minute in the setup method. I then wait 10 seconds after the arduino is booted.. When i then press the button the serial outputs the last 10 seconds at once, like the timer had been on from the start, even though my code shows that the button is supposed to enable and start the timer..

include "CountUpDownTimer.h"

CountUpDownTimer T(DOWN);

const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;

bool tmpBool=false; bool oneTimer=false;

void setup() { pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(115200); T.SetTimer(0,1,0); }

void loop() { buttonState = digitalRead(buttonPin); if(buttonState==HIGH || tmpBool==true) {
digitalWrite(ledPin, HIGH);
tmpBool=true; if(oneTimer==false) { T.StartTimer(); oneTimer=true; } T.Timer(); if (T.TimeHasChanged() ) { Serial.print(T.ShowHours()); Serial.print(":"); Serial.print(T.ShowMinutes()); Serial.print(":"); Serial.print(T.ShowSeconds()); Serial.print(":"); Serial.print(T.ShowMilliSeconds()); Serial.print(":"); Serial.println(T.ShowMicroSeconds()); } } else { digitalWrite(ledPin, LOW); } } — Reply to this email directly or view it on GitHub.

PingPongLee commented 9 years ago

Yes it has, i simply followed the basic arduino button tutorial to make sure it was done right

http://www.arduino.cc/en/Tutorial/Button

AndrewMascolo commented 9 years ago

I will look into it.

From: PingPongLee [mailto:notifications@github.com] Sent: Saturday, May 23, 2015 5:21 PM To: AndrewMascolo/CountUpDownTimer Cc: AndrewMascolo Subject: Re: [CountUpDownTimer] Timer starts even though the StartTimer method isnt called (#2)

Yes it has, i simply followed the basic arduino button tutorial to make sure it was done right

http://www.arduino.cc/en/Tutorial/Button

— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/2#issuecomment-104945333 . https://github.com/notifications/beacon/AIon3s2Jtt-S5OV8jjWF_Shyog22bhwqks5oMObJgaJpZM4EmoWP.gif

AndrewMascolo commented 9 years ago

Problem was solved, please redownload the library.

From: PingPongLee [mailto:notifications@github.com] Sent: Saturday, May 23, 2015 5:21 PM To: AndrewMascolo/CountUpDownTimer Cc: AndrewMascolo Subject: Re: [CountUpDownTimer] Timer starts even though the StartTimer method isnt called (#2)

Yes it has, i simply followed the basic arduino button tutorial to make sure it was done right

http://www.arduino.cc/en/Tutorial/Button

— Reply to this email directly or view it on GitHub https://github.com/AndrewMascolo/CountUpDownTimer/issues/2#issuecomment-104945333 . https://github.com/notifications/beacon/AIon3s2Jtt-S5OV8jjWF_Shyog22bhwqks5oMObJgaJpZM4EmoWP.gif

PingPongLee commented 9 years ago

This did the trick in both my projects. I supposed that hte CountUpDownTimer library is the library you are working on, which replaced the CountDownTimer library am i right?

AndrewMascolo commented 9 years ago

Yes, I prefer people use this one but I know some already have the older one so I don't want to take it down.

Sent from my iPhone

On May 24, 2015, at 4:21 AM, PingPongLee notifications@github.com wrote:

This did the trick in both my projects. I supposed that hte CountUpDownTimer library is the library you are working on, which replaced the CountDownTimer library am i right?

— Reply to this email directly or view it on GitHub.

lcorreaesbr commented 9 years ago

Hi, I want to display only seconds (two digits) dot miliseconds (one digit) in this format: ss.m what sould I change to get this?

In the libary or in the sprintf format? Can you post some code example?

Thanks in advance!

AndrewMascolo commented 9 years ago

Dont use sprintf(), it uses up too much memory.

Just do this.

(code, not tested) char time[5]; // create a buffer large enough to hold everything time[0] = '0' + (T.ShowSeconds() / 10); // tens place *note the '0' makes the value a char time[1] = '0' + (T.ShowSeconds() % 10); // ones place time[2] = '.' ; // add decimal point time[3] = '0' + (T.ShowMilliSeconds() % 10); // 0 - 9 time[4] = 0; //NULL

Serial.println(time);

lcorreaesbr commented 9 years ago

Hi Thanks for your fast reply!!!

I´ve tested and seems that is almost there..

I belive that I get tree/ four times the same value... This is what i get:

00.0 (first) 00.1 00.2 00.3 00.4 00.6 00.7 00.8 00.9 00.0 (second) 00.1 00.2 00.3 00.4 00.5 00.6 00.7 00.8 00.9 00.0 (third) 00.1 00.2 00.3 00.4 00.5 00.6 00.7 00.8 00.9 00.0 (four) 01.0 (first) 01.1 01.2 01.3 01.4 01.5 01.6 01.7 01.8 01.9 01.0 (second) 01.1 01.2 01.3 01.4 01.5 01.6 01.7 01.8 01.9 01.0 (third) 01.1 01.2 01.3 01.4 01.5 01.6 01.7 01.8 and so on...

Thanks for your support!

AndrewMascolo commented 9 years ago

Sorry for not responding yesterday. Ok I would need to see your code.

lcorreaesbr commented 9 years ago

Hi, no problem! I'm home now, tomorrow I send you the code. Thank you!

Em 01/09/2015, às 11:00, AndrewMascolo notifications@github.com escreveu:

Sorry for not responding yesterday. Ok I would need to see your code.

— Reply to this email directly or view it on GitHub.