Up-Down Timer

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Up-Down Timer

Post by rbytes »

This timer program uses much of the same code as Big Clock. I found a very nice Chrome colorfont to display the digits. All of the attached images other than the two screenshots need to be downloaded into a RESOURCES folder in the same location as the program.

There is an onscreen keyboard issue. Sometimes it won't appear automatically, and it must always be hidden manually before you start the timer. I will post this finding in Bug Reports.

Code: Select all

''
UD Timer Chrome by rbytes
August 2017
Up-Down timer
Uses graphic images of the 10 digits, the colon
and the 'Done' message
''
' ########################  Set Count Duration ###############################
maxt = 20 'total seconds to be timed
' ############################################################################

cnt = 0
'#.drawrect(160,255,343,500)        ' used only for setting digit sizes and offsets
xn=[31,200,455,620,865,1035]          ' reference x positions using p variable
hn=110;yn=230                       ' reference height and y position
#.scrclear(1,1,1)

' the character images vary in size and xy offsets so this array stores correction data
q=[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]

' the "s" flags prevent #.image and show being executed more than once per image object
s1,s2,s3,s4,s5,s6 = 0

' the "flag" flags only allow any digit to be refreshed once when a second, minute or hour changes
flag1,flag2,flag3,flag4,flag5,flag6 = 0

' runflag starts the timing loop when it = 1
runflag = 0

#.output("Enter the total seconds to be timed, then press Return")
maxtt = #.input()
#.output("You entered "+maxtt+" seconds")

maxt=#.val(maxtt)

#.output("Press 0 to count down or 1 to count up, then press Return")
udflag = #.input()
#.output("You entered "+udflag)
udflg = #.val(udflag)

#.delay(1)
#.clear()
#.scrclear(.5,.5,.5)

' start button
butt=#.button
  butt.height = 50
  butt.text = "S T A R T"
  butt.width = 120
  butt.x = 550
  butt.y = 450
#.show(butt)

' draw the left colon
b = #.image                       ' colon image
b.source = "resources\Ccolon.png"
b.height = 80
b.x = 380
b.y = 250
#.show(b)

' draw the right colon
c = #.image                       ' colon image
c.source = "resources\Ccolon.png"
c.height = 80
c.x = 795
c.y = 250
#.show(c)

' set t depending on whether the count is down or up
? udflg = 1
  t=0
!
  t=maxt
.

>
' MAIN PROGRAM LOOP

' convert seconds into hours, minutes and seconds
hor,min,sec=gett(t)

' increment the loop counter
cnt += 1

' units of seconds
sc = #.int(sec-(sec>9)*#.lower(sec/10)*10)
? sc=0, sc = 10
e6 = sc
p = 6
? e6 != flag6
  nm="resources\C"+e6+".png"
  h=hn+q[1,e6];x=xn[p]+q[2,e6];y=yn+q[3,e6]
  f6(s6,nm,h,x,y)
.
flag6 = e6
s6 = 1

' tens of seconds
sect = #.lower(sec/10)
? sect=0, sect = 10
e5 = sect
p=5
? e5 != flag5
  nm="resources\C"+e5+".png"
  h=hn+q[1,e5];x=xn[p]+q[2,e5];y=yn+q[3,e5]
  ? e5 = 1, x += 95
  f5(s5,nm,h,x,y)
.
flag5 = e5
s5 = 1

' units of minutes
mn = #.int(min-(min>9)*#.lower(min/10)*10)
? mn=0, mn = 10
e4 = mn
p=4
? e4 != flag4
  nm="resources\C"+e4+".png"
  h=hn+q[1,e4];x=xn[p]+q[2,e4];y=yn+q[3,e4]
  f4(s4,nm,h,x,y)
.
flag4 = e4
s4 = 1

' tens of minutes
mint = #.lower(min/10)
? mint=0, mint = 10
e3 = mint
p=3
? e3 != flag3
  nm="resources\C"+e3+".png"
  h=hn+q[1,e3];x=xn[p]+q[2,e3];y=yn+q[3,e3]
  ? e3 = 1, x += 90
  f3(s3,nm,h,x,y)
.
flag3 = e3
s3 = 1

' units of hours
hr = #.int(hor-(hor>9)*#.lower(hor/10)*10)
? hr=0, hr = 10
e2 = hr
p=2
? e2 != flag2
  nm="resources\C"+e2+".png"
  h=hn+q[1,e2];x=xn[p]+q[2,e2];y=yn+q[3,e2]
  f2(s2,nm,h,x,y)
.
flag2 = e2
s2 = 1

' tens of hours
hort = #.lower(hor/10)
? hort=0, hort = 10
e1 = hort
p=1
? e1 != flag1
  nm="resources\C"+e1+".png"
  h=hn+q[1,e1];x=xn[p]+q[2,e1];y=yn+q[3,e1]
  ? e1 = 1, x += 100
  f1(s1,nm,h,x,y)
.
flag1 = e1
s1 = 1
#.delay(1)
? udflg = 1
  t += 1
  loopflg = maxt + 1
!
  t -= 1
.

' wait until the start button is pushed 
:test
? #.act(butt) = 1 | runflag = 1
  ' when the start button is pushed, we need a 1 second delay before the count changes
  ? runflag = 0, #.delay(1)
  ' the runflag variable keeps the timing loop running even though the Start button is pressed just once
  runflag = 1
  again ->
! 
  ' add a short delay to slow down the test loop
  #.delay(.1)
  test ->
.

' repeat the timing loop
:again
< cnt < maxt + 1

#.scrclear(1,0,0)

' draw the Done message
dn = #.image                       ' Done image
dn.source = "resources\CDone.png"
dn.width = 500
dn.x = 365
dn.y = 600
#.show(dn)
'd.height = 500

#.end()

' calculates hours, minutes and seconds from t (total seconds)
gett(t)=
  hor = #.lower(t/3600)
  min = #.lower((t-hor*3600)/60)
  sec = t%60
  <= hor,min,sec  ' returns values
.

f1(s1,src,h,x,y) =      ' hours tens digit
  ? s1=0
    i1 = #.image
  .
  i1.source = src
  i1.height = h
  i1.x = x
  i1.y = y
  ? s1=0, #.show(i1)
.

f2(s2,src,h,x,y) =      ' hours units digit
  ? s2=0
    i2 = #.image
  .
'  i2 = #.image
  i2.source = src
  i2.height = h
  i2.x = x
  i2.y = y
  ? s2=0, #.show(i2)
.

f3(s3,src,h,x,y) =      ' minutes tens digit
  ? s3=0
    i3 = #.image
  .
'  i3 = #.image
  i3.source = src
  i3.height = h
  i3.x = x
  i3.y = y
  ? s3=0, #.show(i3)
.

f4(s4,src,h,x,y) =      ' minutes units digit
  ? s4=0
    i4 = #.image
  .
'  i4 = #.image
  i4.source = src
  i4.height = h
  i4.x = x
  i4.y = y
  ? s4=0, #.show(i4)
.

f5(s5,src,h,x,y) =      ' seconds tens digit
  ? s5=0
    i5 = #.image
  .
'  i5 = #.image
  i5.source = src
  i5.height = h
  i5.x = x
  i5.y = y
  ? s5=0, #.show(i5)
.

f6(s6,src,h,x,y) =      ' seconds units digit
  ? s6 = 0
    i6 = #.image
  .
  i6.source = src
  i6.height = h
  i6.x = x
  i6.y = y
  ? s6 = 0, #.show(i6)
.
Attachments
Screenshot (21).png
Screenshot (21).png (80.13 KiB) Viewed 1435 times
Screenshot (22).png
Screenshot (22).png (127.86 KiB) Viewed 1435 times
CDone.png
CDone.png (34.82 KiB) Viewed 1435 times
Ccolon.png
Ccolon.png (7.7 KiB) Viewed 1435 times
C10.png
C10.png (9.6 KiB) Viewed 1435 times
C9.png
C9.png (8.75 KiB) Viewed 1435 times
C8.png
C8.png (9.52 KiB) Viewed 1435 times
C7.png
C7.png (7.42 KiB) Viewed 1435 times
C6.png
C6.png (8.37 KiB) Viewed 1435 times
C5.png
C5.png (8.82 KiB) Viewed 1435 times
C4.png
C4.png (7.76 KiB) Viewed 1435 times
C3.png
C3.png (8.97 KiB) Viewed 1435 times
C2.png
C2.png (8.65 KiB) Viewed 1435 times
C1.png
C1.png (4.43 KiB) Viewed 1435 times
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Up-Down Timer

Post by Mr. Kibernetik »

Suggestion: to create setup mode when user sets timer time before run, for example using special buttons above and below digits.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Up-Down Timer

Post by rbytes »

Good idea. Thanks.
The only thing that gets me down is gravity...

Post Reply