Go Down

Topic: LED clock with different time speed (Read 4533 times) previous topic - next topic

Graynomad

#30
Sep 21, 2010, 06:24 am Last Edit: Sep 21, 2010, 06:27 am by graynomad Reason: 1
Code: [Select]
     slow_display = TRUE;
This shouldn't have been there, I was playing with another option and forgot to take it out.

That's your compiler error but not the logic problem.

One way or another there should ba some kind of display even 000000, is that the case?
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus


Graynomad

Comment out this

Code: [Select]
// detect falling edge of button
  // record the time and set flag to indicate we are timing for 10 secs
  if (digitalRead (BUTTON) == LOW && button_state == HIGH) {
        time_but_pressed = millis();
        button_state == LOW;
       timing = TRUE;
  }

  // if it's been 10secs since we started timing reset the flag
  if (millis () > time_but_pressed + 10 * 1000) {
     timing = FALSE;
  }


So now we're almost back to the working code. What happens?
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus

If comment out means take away, then we are counting seconds again.

Graynomad

Quote
If comment out means take away

Pretty much, you can just cut the text or wrap it in /* */ comment codes.

So there's a problem in that piece of code, put it back and remove one of the "if" blocks, see what happens, then put that back and remove the other and see what happens. Try to determine exactly which line of code causes the problem.

Meanwhile I'll have a think.
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus

I took away the second if and then it counts but nothing happens when I press the button. Haven't doublechecked the button though but its time for the bed.

Graynomad

Two problems, one small one big.

Initialise the timing variable

Code: [Select]
unsigned int timing = FALSE;

And the classic C gotcha

Code: [Select]
if (ticks = 0) {

should be

Code: [Select]
if (ticks == 0) {

Still may not be right but no chance with that.
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus

Quote
Still may not be right but no chance with that.

Nope, but it counts with both "if" in the code now but no action when button is pressed.
I made a testsketch for the button setup and the button is wired correctly.

sinuslinus

I am trying to understand and as far as I can see there is nothing saying that all displays should be counting the "ticks".
Now it acts as the previous counter ss:mm:hh

I put an extra pair of brackets after tick and now it counts 1/10th seconds but still just the first digit and then when hitting the highs pushes over to the next one.

Code: [Select]
[glow]{[/glow]if (seconds > 59) {
     seconds = 0;
     minutes++;
  }
  if (minutes > 59) {
     minutes = 0;
     hours++;
  }
  if (hours > 23) {
     hours = 0;
  }[glow]}[/glow]

Graynomad

#39
Sep 21, 2010, 04:08 pm Last Edit: Sep 21, 2010, 04:12 pm by graynomad Reason: 1
Back up a bit.

Quote
but it counts with both "if" in the code now but no action when button is pressed.


Is this still the case (without the new braces) and how fast does it count?

Quote
Now it acts as the previous counter ss:mm:hh

All it should do at present is count the same either way, just slower when the button is pressed.
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus

#40
Sep 21, 2010, 04:15 pm Last Edit: Sep 21, 2010, 04:19 pm by sinuslinus Reason: 1
Weird, it counts the same without the brackets. Wonder what I was looking at... So the brackets do nothing.

Code: [Select]
All it should do at present is count the same either way, just slower when the button is pressed.

No action when pressing button.

Graynomad

Code: [Select]
  if (timing == FALSE) {
[glow]     digitalWrite(latchpin, LOW);
     for (int x = 0; x < 6; x++)
        shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
     digitalWrite(latchpin, HIGH);  [/glow]  
} else {
     if (ticks == 0) {
        digitalWrite(latchpin, LOW);
        for (int x = 0; x < 6; x++)
           shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
        digitalWrite(latchpin, HIGH);  
     }
  }  


If we are not timing the 10 seconds the yellow bit gets executed 10 times a sec.

If we are timing the other half runs and this tests for tick == 0, therefore it only runs every 10 times, ie every second.
Rob Gray aka the GRAYnomad www.robgray.com

Graynomad

#42
Sep 21, 2010, 04:22 pm Last Edit: Sep 21, 2010, 04:23 pm by graynomad Reason: 1
What speed is it counting at?

Quote
No action when pressing button.

Do you mean it stops or that nothing changes?
Rob Gray aka the GRAYnomad www.robgray.com

sinuslinus

Okay,

it counts 10th of seconds.
When I press the button nothing changes.

Graynomad

Change

Code: [Select]
  if (timing == FALSE) {


to

Code: [Select]
timing = TRUE;
  if (timing == FALSE) {


Does it now count at 1Hz?
Rob Gray aka the GRAYnomad www.robgray.com

Go Up