Countdown question

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Countdown question

Post by dazz »

Hi
Ive just done my first project in flowcode (using bits of code from the forum). What it does is to switch on uv leds for a pcb exposure box im making, so my question is how do i get the display to countdown ( ive managed the minutes) but i'd also like some pointers to add seconds to the display, the other thing is as im still very new to this is there a better way of doing the flowcode than the way i did it. i think ive calculated the timer right to get seconds. any pointers would be appreciated,

regards
Attachments
pcbtimer.fcf
(54.78 KiB) Downloaded 316 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Countdown question

Post by dazz »

i've managed to get second into the display but when the seconds get down past 10, the unit digit goes to the left so seven seconds displays as 70, five seconds as 50 etc, how do i get it to display the single numbers properly, and is there a way to have the minutes display with a leading zero ie 03 instead of 3

I must thank medelec for his tmr postings as it enabled me to finaly figure timers out, and als his button press code as it works a treat for my project ( oh and spent hours here checking code a writing to chip as i could get it to work in sim but not on hardware, then it dawned on me i hadnt set the trm0 to use the internal clock)doh doh doh

Lastly is there any way to count down the last minute in seconds as i can only manage to get it to switch off the outputs when minutes =0 (which leaves it 60 seconds short)

but apart from the few display issues above it works well on my hardware
Attachments
pcbtimer.fcf
(56.47 KiB) Downloaded 311 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Countdown question

Post by JonnyW »

I'm afraid I can't look at your flowchart at the moment as I'm on a Linux box so this may all be nonsense but I would suggest that when doing any timings keep everything in the smallest unit possible. So don't treat minutes separate from seconds, treat it as one counter (minutes * 60 + seconds). This makes all the logic much easier to deal with, and should also solve your issue with stopping 60 seconds early.

Only when you display the value should you need to convert to minutes and seconds:

Code: Select all

  minutes = timer / 60
  seconds = timer % 60
And then to convert seconds to a string do in a calculation icon:

Code: Select all

  buffer = ToString$(seconds)
  if (seconds < 10)
    buffer = "0" + buffer // Pad to 2 digits
If you are some way in and don't want to redo everything as a single counter, the lines below in a decision icon may help:

Code: Select all

(minutes > 0 || seconds > 0) // Will take the 'yes' branch if your counter is not zero
(minutes == 0 && seconds == 0) // Will take the 'yes' branch if your counter has reached zero
I hope any of this is useful,

Jonny

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Countdown question

Post by medelec35 »

Hi dazz,
Glad I have been able to help you out.
Hopefully this might help you out further.
Attach is a count down timer I designed for someone, since they wanted to fall asleep with the lamp on.
The Idea is as soon as want the lamp on you press the up key (above OK ) then timer will start at 15 mins 00 seconds and count down. pressing up will increment for a further 15mins of down will decrement 15mins. Green will take time to 90 mins and Red will reset to 0

The way this may help you is countdown stops when reaches 0 mins and 0 seconds
There is a semicolon that flashes every seconds like digital clocks.
Finally there is a leading 0 for seconds if less then 10.

Martin
Attachments
Count down Timer Miac FC5.fcf
(18.4 KiB) Downloaded 371 times
Martin

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Countdown question

Post by dazz »

Thanks fellas, i couldnt believe how simple the answer was and it allowed me to tidy up my chart a bit, onto the next bit now

thanks again
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Post Reply