Pages: 1 2 3 [4]   Go Down
Author Topic: LED clock with different time speed  (Read 4130 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Add the yellow line

Code:
  // if it's been 10secs since we started timing reset the flag
   if (millis () > time_but_pressed + 10 * 1000) {
 [glow]     button_state == HIGH;[/glow]      
      timing = FALSE;
   }
« Last Edit: September 21, 2010, 09:38:52 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It counts at 1 Hz on two displays simultanously at first and then when it hits 10 it differ on number.
No change when pressing button.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Comment out these two lines

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

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

counting properly at 10 Hz , still no change with button.

I tried both with and without
Code:
timing = TRUE;
as you earlier post and both and without
Code:
if (ticks == 0) {
« Last Edit: September 21, 2010, 10:04:48 am by sinuslinus » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Put that lot back, it should look like this

Code:
timing = TRUE;
   if (timing == FALSE) {
      digitalWrite(latchpin, LOW);
      for (int x = 0; x < 6; x++)
         shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
      digitalWrite(latchpin, HIGH);  
   } else {
      if (ticks == 0) {
         digitalWrite(latchpin, LOW);
         for (int x = 0; x < 6; x++)
            shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
         digitalWrite(latchpin, HIGH);  
      }
   }  
« Last Edit: September 21, 2010, 11:15:02 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Found two more bugs. Change the two settings of button state from

Code:
        button_state [glow]==[/glow] HIGH;
         button_state [glow]==[/glow] LOW;

to

Code:
        button_state = HIGH;
         button_state = LOW;


Can you post the entire code you have, I'm worried we're singing from different hymn sheets.
« Last Edit: September 21, 2010, 11:00:19 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Haven't test run these last changes but here is what we have now. Will do later tonight so I guess that will be morning for you.

Can you double check those == and = because I have now change three == to = according to your last post.

Code:
#define SECONDS 4
#define MINUTES 2
#define HOURS   0


#define TRUE 1  // these may cause an error if already defined
#define FALSE 0
#define BUTTON 5 // push button on pin 5


unsigned int latchpin = 8;  // connect to pin 12 on the '595
unsigned int clockpin = 12; // connect to pin 11 on the '595
unsigned int datapin  = 11; // connect to pin 14 on the '595

unsigned int speed = 1000;    // used to control speed of counting
unsigned int ticks = 0;
unsigned int seconds = 0;
unsigned int minutes = 0;
unsigned int hours = 0;
unsigned int digits[6];
unsigned int button_state = HIGH;
unsigned long time_but_pressed;

unsigned int timing = FALSE;

unsigned int segdisp[10] = {63,6,91,79,102,109,125,7,127,111};

void setup() {

   pinMode(latchpin, OUTPUT);
   pinMode(clockpin, OUTPUT);
   pinMode(datapin, OUTPUT);

}

void loop(){
  {
   ticks++;
   if (ticks > 10)
      ticks = 0;
      seconds++;
    }
   if (seconds > 59) {
      seconds = 0;
      minutes++;
   }
   if (minutes > 59) {
      minutes = 0;
      hours++;
   }
   if (hours > 23) {
      hours = 0;
   }

  // 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
   // if it's been 10secs since we started timing reset the flag
    (millis () > time_but_pressed + 10 * 1000); {
      button_state = HIGH;
      timing = FALSE;
   }
   digits[SECONDS]   = seconds / 10;
   digits[SECONDS+1] = seconds % 10;
   digits[MINUTES]   = minutes / 10;
   digits[MINUTES+1] = minutes % 10;
   digits[HOURS]     = hours   / 10;
   digits[HOURS+1]   = hours   % 10;

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


   delay (100);
}
 
« Last Edit: September 21, 2010, 11:32:25 am by sinuslinus » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just check two of those "if"s, they are located pretty wierdly. Apart form that it looks OK.

It should now count slowly.

To test if the button is actually working replace

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

with

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


So we can see exactly what is being returned by the button. Presumably it should be 111111 when the button is not pressed and 000000 when it is.
« Last Edit: September 21, 2010, 11:45:46 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Presumably it should be 111111 when the button is not pressed and 000000 when it is.

It is the opposite;
111111 when pressed and
000000 when not pressed.

The code posted counts at 1Hz to 59 on the two seconds displays but in a weird way. It is as I wrote before firstly simultaneously but then weird because the 10 second just counts to 6 (as if to 59).
11,22,33,44,55,06,17,28,39...

If I comment out timing = TRUE then it counts at 10 Hz properly up to 59
Code:
//timing = TRUE;
   if (timing == FALSE) {
      digitalWrite(latchpin, LOW);
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I sent you a PM, can you email me all the current code?

« Last Edit: September 21, 2010, 11:31:13 pm by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Still can't send email.

Your compiling problem:

unsigned int segdisp = {63,6,91,79,102,109,125,7,127,111};

to

unsigned int segdisp[10] = {63,6,91,79,102,109,125,7,127,111};

actuall ytake the entire code, who knows what else was stuffed up in the PM

#define SECONDS 4
#define MINUTES 2
#define HOURS   0


#define TRUE 1  // these may cause an error if already defined
#define FALSE 0
#define BUTTON 5 // push button on pin 5


unsigned int latchpin = 8;  // connect to pin 12 on the '595
unsigned int clockpin = 12; // connect to pin 11 on the '595
unsigned int datapin  = 11; // connect to pin 14 on the '595

unsigned int speed = 1000;  // used to control speed of counting
unsigned int ticks = 0;
unsigned int seconds = 0;
unsigned int minutes = 0;
unsigned int hours = 0;
unsigned int digits[6];
unsigned int button_state = HIGH;
unsigned long time_but_pressed;

unsigned int timing = FALSE;

unsigned int segdisp[10] = {63,6,91,79,102,109,125,7,127,111};

void setup() {

   pinMode(latchpin, OUTPUT);
   pinMode(clockpin, OUTPUT);
   pinMode(datapin, OUTPUT);

}

void loop(){
   ticks++;

   if (ticks > 9) {
      ticks = 0;
      seconds++;
      if (seconds > 59) {
         seconds = 0;
         minutes++;
      }
      if (minutes > 59) {
         minutes = 0;
         hours++;
      }
      if (hours > 23) {
         hours = 0;
        }
    }

    digits[SECONDS+1] = seconds % 10; // 5  1s
    digits[SECONDS]   = seconds / 10; // 4  10s
    digits[MINUTES+1] = minutes % 10; // 3  1s
    digits[MINUTES]   = minutes / 10; // 2  10s
    digits[HOURS+1]   = hours   % 10; // 1  1s
    digits[HOURS]     = hours   / 10; // 0  10s
    
    if (digitalRead (BUTTON) == HIGH)
       timing = TRUE;
    else
       timing = FALSE;
    
    
    if (timing == FALSE) {
        writeDigits(1);
    } else {
       if (ticks == 0) writeDigits(2);
    }

    delay (100);
}
 
void writeDigits (int xx) {
    digitalWrite(latchpin, LOW);
    for (int x = 0; x < 6; x++)
       shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits
  • ]);
   digitalWrite(latchpin, HIGH);  
}
« Last Edit: September 22, 2010, 12:23:55 pm by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1:30AM here, gotta hit the sack. Email me with results from last version.
Logged

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob helped me a lot with this one and I have it working now. It counts at 10 Hz 0-9 on all segments simultaneously and when you press the button it displays the time hh:mm:ss.

The last thing I want to finish this is to display the time 10 seconds after the button is pressed.
That is, quicker counter without button and with button it displays time at 1 Hz and should keep this for 10 seconds before going back to the quick counter.

This is the working code.

Code:
#define TRUE 1  // these may cause an error if already defined
#define FALSE 0
#define BUTTON 5 // push button on pin 5

#define SECONDS 4
#define MINUTES 2
#define HOURS   0


unsigned int latchpin = 8;  // connect to pin 12 on the '595
unsigned int clockpin = 12; // connect to pin 11 on the '595
unsigned int datapin  = 11; // connect to pin 14 on the '595

unsigned int ticks = 0;
unsigned int seconds = 0;
unsigned int minutes = 0;
unsigned int hours = 0;
unsigned int digits[6];
unsigned int button_state = HIGH;
unsigned long time_but_pressed;

unsigned int timing = FALSE;

unsigned int segdisp[10] = {63,6,91,79,102,109,125,7,127,111};

void setup() {

  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);

}

void loop(){
  ticks++;

  if (ticks > 9) {
     ticks = 0;
     seconds++;
     if (seconds > 59) {
        seconds = 0;
        minutes++;
     }
     if (minutes > 59) {
        minutes = 0;
        hours++;
     }
     if (hours > 23) {
        hours = 0;
       }
   }

   digits[SECONDS+1] = seconds % 10; // 5  1s
   digits[SECONDS]   = seconds / 10; // 4  10s
   digits[MINUTES+1] = minutes % 10; // 3  1s
   digits[MINUTES]   = minutes / 10; // 2  10s
   digits[HOURS+1]   = hours   % 10; // 1  1s
   digits[HOURS]     = hours   / 10; // 0  10s

   if (digitalRead (BUTTON) == HIGH)
      timing = TRUE;
   else
      timing = FALSE;


   if (timing == FALSE) {
      writeDigits(ticks);
   } else {
      writeDigits1();
   }

   delay (100);
}

void writeDigits (int xx) {
   digitalWrite(latchpin, LOW);
   for (int x = 0; x < 6; x++)
      shiftOut(datapin, clockpin, MSBFIRST, segdisp[xx]);
   digitalWrite(latchpin, HIGH);  
}

void writeDigits1 () {
   digitalWrite(latchpin, LOW);
   for (int x = 0; x < 6; x++)
      shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
   digitalWrite(latchpin, HIGH);  
}


Can someone with fresh eyes read it through, please.

Have tried to add this the delay but then there is no change when the button is pressed
Code:
#define TRUE 1  // these may cause an error if already defined
#define FALSE 0
#define BUTTON 5 // push button on pin 5

#define SECONDS 4
#define MINUTES 2
#define HOURS   0


unsigned int latchpin = 8;  // connect to pin 12 on the '595
unsigned int clockpin = 12; // connect to pin 11 on the '595
unsigned int datapin  = 11; // connect to pin 14 on the '595

unsigned int ticks = 0;
unsigned int seconds = 0;
unsigned int minutes = 0;
unsigned int hours = 0;
unsigned int digits[6];
unsigned int button_state = HIGH;
unsigned long time_but_pressed;

unsigned int timing = FALSE;

unsigned int segdisp[10] = {63,6,91,79,102,109,125,7,127,111};

void setup() {

  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);

}

void loop(){
  ticks++;

  if (ticks > 9) {
     ticks = 0;
     seconds++;
     if (seconds > 59) {
        seconds = 0;
        minutes++;
     }
     if (minutes > 59) {
        minutes = 0;
        hours++;
     }
     if (hours > 23) {
        hours = 0;
       }
   }

   digits[SECONDS+1] = seconds % 10; // 5  1s
   digits[SECONDS]   = seconds / 10; // 4  10s
   digits[MINUTES+1] = minutes % 10; // 3  1s
   digits[MINUTES]   = minutes / 10; // 2  10s
   digits[HOURS+1]   = hours   % 10; // 1  1s
   digits[HOURS]     = hours   / 10; // 0  10s


  // 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); {
    button_state = HIGH;
    timing = FALSE;
  }



   if (timing == FALSE) {
      writeDigits(ticks);
   } else {
      writeDigits1();
   }

   delay (100);
}

void writeDigits (int xx) {
   digitalWrite(latchpin, LOW);
   for (int x = 0; x < 6; x++)
      shiftOut(datapin, clockpin, MSBFIRST, segdisp[xx]);
   digitalWrite(latchpin, HIGH);  
}

void writeDigits1 () {
   digitalWrite(latchpin, LOW);
   for (int x = 0; x < 6; x++)
      shiftOut(datapin, clockpin, MSBFIRST, segdisp[digits[x]]);
   digitalWrite(latchpin, HIGH);  
}

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

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

/ Linus
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: