BASIC Code wrote:
:real(7,0
:SetUpEditor∟CL
:11→dim(∟CL
:ClrHome
:Disp "LAST ENTRY:
:Disp ∟CL(10
:Disp "TIME DELAY (S)?
:Input θ
:θ→∟CL(10
:[[8,0,θ][8,50,θ][8,55,θ][9,45,θ][9,50,θ][10,40,θ][10,45,θ][11,0,θ][11,5,θ][11,55,θ][12,0,θ][12,30,θ][12,35,θ][12,55,θ][13,0,θ][13,5,θ][13,30,θ][13,35,θ][14,25,θ][14,30,θ][15,20,θ]]→[A]
:[[1,5][1,12][1,19][1,26][2,2][2,9][2,16][2,23][3,2][3,9][3,16][3,23][3,30][4,6][4,13][4,20][4,27][5,4][5,11][5,18][5,25][6,1][6,8][6,15][6,22][6,29][7,6][7,13][7,20][7,27][8,3][8,10][8,17][8,24][8,31][9,7][9,14][9,21][9,28][10,5][10,12][10,19][10,26][11,2][11,9][11,16][11,23][11,30][12,7][12,14][12,21][12,28]]→[B]
:getDate→L1
:For(X,1,52
:¦ If L1(2)=[B](X,1) and L1(3)=[B](X,2
:¦ 9090→K
:End
:If K=9090
:[[8,20,θ][9,10,θ][9,15,θ][10,5,θ][10,10,θ][11,0,θ][11,5,θ][11,55,θ][12,0,θ][12,30,θ][12,35,θ][12,55,θ][13,0,θ][13,5,θ][13,30,θ][13,35,θ][14,25,θ][14,30,θ][15,20,θ]]→[A]
:DelVar [B]DelVar KDelVar X
:ClrHome
:Output(2,3,"Hour
:Output(2,8,"Min
:Output(2,12,"Sec
:Output(5,4,"Time Left
:Output(6,3,"Hour
:Output(6,8,"Min
:Output(6,12,"Sec
:1→W
:While W=1
:¦ getTime→L1
:¦ θ+3600L1(1)+60L1(2)+L1(3→K
:¦ 1→∟CL(11
:¦ For(X,1,21
:¦ ¦ If K>(3600[A](X,1)+60[A](X,2)+[A](X,3
:¦ ¦ 1+∟CL(11→∟CL(11
:¦ End
:¦ If 21<∟CL(11
:¦ 1→∟CL(11
:¦ For(X,1,3
:¦ ¦ [A](∟CL(11),X→∟CL(X+3
:¦ End
:¦ 2→W
:¦ While W=2
:¦ ¦ getKey→K
:¦ ¦ If K=45:0→W
:¦ ¦ real(7,0
:¦ ¦ getTime→L1
:¦ ¦ For(X,1,3
:¦ ¦ ¦ L1(X→∟CL(X
:¦ ¦ End
:¦ ¦ If 10>∟CL(1
:¦ ¦ Then
:¦ ¦ ¦ Output(3,3,"0
:¦ ¦ ¦ Output(3,4,∟CL(1
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,3,∟CL(1
:¦ ¦ End
:¦ ¦ If 10>∟CL(2
:¦ ¦ Then
:¦ ¦ ¦ Output(3,8,"0
:¦ ¦ ¦ Output(3,9,∟CL(2
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,8,∟CL(2
:¦ ¦ End
:¦ ¦ If 10>∟CL(3
:¦ ¦ Then
:¦ ¦ ¦ Output(3,12,"0
:¦ ¦ ¦ Output(3,13,∟CL(3
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,12,∟CL(3
:¦ ¦ End
:¦ ¦ 3600(∟CL(4)-L1(1))+60(∟CL(5)-L1(2))+∟CL(6)-∟CL(3→V
:¦ ¦ "If 0>V
:¦ ¦ "86400+V→V
:¦ ¦ int(V/3600→∟CL(7
:¦ ¦ int(60(V/3600-int(V/3600→∟CL(8
:¦ ¦ V-3600∟CL(7)-60∟CL(8→∟CL(9
:¦ ¦ If 10>∟CL(7
:¦ ¦ Then
:¦ ¦ ¦ Output(7,3,"0
:¦ ¦ ¦ Output(7,4,∟CL(7
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,3,∟CL(7
:¦ ¦ End
:¦ ¦ If 10>∟CL(8
:¦ ¦ Then
:¦ ¦ ¦ Output(7,8,"0
:¦ ¦ ¦ Output(7,9,∟CL(8
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,8,∟CL(8
:¦ ¦ End
:¦ ¦ If 10>∟CL(9
:¦ ¦ Then
:¦ ¦ ¦ Output(7,12,"0
:¦ ¦ ¦ Output(7,13,∟CL(9
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,12,∟CL(9
:¦ ¦ End
:¦ ¦ If V≤0
:¦ ¦ 1→W
:¦ End
:End
:DelVar [A]DelVar KDelVar XDelVar L1
:SetUpEditor
:ClrHome
Generated by SourceCoder, © 2005-2011 Cemetech
This is a program I made to experiment with the getTime function.

Our school clock is usually behind a few seconds when it rings the bell, so the opening asks for the delay in seconds, if there is one. Then it checks if the day is Wednesday or not (we have a slightly different schedule on Weds.). Then the program shows a digital clock on the top half of the screen (military time) and displays a countdown to the end of class/passing period on the bottom half.

How can I optimize this? I hate it being sooooooo slow (actual calc clock time and countdown time are usually 1/4-1/2 seconds off, and the calc clock display lags and speeds up). And yes, I need to make this non-DCS compatible, so no real() commands or anything.
Can you explain what matrices [A] and [B] contain? I'm pretty sure those need not be pre-defined like that and can be eliminated to save space and speed. Smile
Matrix A is the schedule of when the bells ring (so I can have a countdown to the end of class), and Matrix B is a temp matrix to check if it is a Wednesday based on the date. I'm not sure how I would get rid of them without eliminating those two functions.
Well, there's an easy formulaic way to get the day of the week:

http://tibasicdev.wikidot.com/day-of-week

Code:
:round(7fPart(dbd(101.5,DE2+M+fPart(.01Y))/7
Thanks, I'll make that change.

Is there any way I can make the whole middle section cleaner (where it updates the time)? I don't like having ":If 10>ListElement:Then:4 lines of code:End" tons of times, but wasn't sure how to shorten it (if the number is less than 10, it will display only 1 digit, leaving the 9 from :59 still there, so it looks weird until it hits 10 seconds and takes up the full 2 slots for the number).
I'm no advanced programmer, but this can save a little bit of space and may help a fraction of a bit Smile

Code:

:Output(2,3,"Hour
:Output(2,8,"Min
:Output(2,12,"Sec
:Output(5,4,"Time Left
:Output(6,3,"Hour
:Output(6,8,"Min
:Output(6,12,"Sec

can be written,

Code:

// "_" indicates one space
:Output(2,3,"Hou _Min_Sec
:Output(5,4,"Time Left
:Output(6,3,"Hou _Min_Sec
Thanks, didn't even notice that. Sad Haven't programmed in 5 months, so my brain isn't catching a lot of stuff (which is why I brought it here Wink ).
Here is a school countdown timer I made a year ago or so. Just wanted to share:
No problem beta Smile
other than that, I think this could improve your while loop, which is;

Code:

:¦ While W=2
:¦ ¦ getKey→K
:¦ ¦ If K=45:0→W

Try this instead

Code:

:While W=2
:Repeat k!=0  //Start of nested loop, != means no equal to btw.
:getKey→K
:end               //end of nested loop.
:If K=45:0→W

Now instead of reading the whole loop (which could take a helluv a time) to look for the key pressed, now you can obtain the key press in a mini-nested loop, and when a key is pressed, the nexted loop breaks, and you're into the loop it's self, with the key already stored Smile try that out and update us Very Happy
Even more optimized:


Code:
:While W=2 
:Repeat k //Start of nested loop, != means no equal to btw.
:getKey→K 
:end               //end of nested loop. 
:If K=45:DelVar W
Good stuff Kerm Smile
That would defeat the purpose of the whole program, would it not? That getKey is there simply as a means for the person to exit the program in such a way that it deletes all the stuff to free up space (so they don't leave it around by pressing the On key). If I change that to a nested loop, it would wait for them to exit the program before the program even ran/updated.
Err sorry Beta, I'm stupid because I didn't even realize that getkey was for the exiting of the loop lol my bad :\
No problem.

Is there any way to optimize the main display section? I still think this is the main source of my delay.


Code:
:¦ ¦ If 10>∟CL(1
:¦ ¦ Then
:¦ ¦ ¦ Output(3,3,"0
:¦ ¦ ¦ Output(3,4,∟CL(1
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,3,∟CL(1
:¦ ¦ End
:¦ ¦ If 10>∟CL(2
:¦ ¦ Then
:¦ ¦ ¦ Output(3,8,"0
:¦ ¦ ¦ Output(3,9,∟CL(2
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,8,∟CL(2
:¦ ¦ End
:¦ ¦ If 10>∟CL(3
:¦ ¦ Then
:¦ ¦ ¦ Output(3,12,"0
:¦ ¦ ¦ Output(3,13,∟CL(3
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(3,12,∟CL(3
:¦ ¦ End

.....

:¦ ¦ If 10>∟CL(7
:¦ ¦ Then
:¦ ¦ ¦ Output(7,3,"0
:¦ ¦ ¦ Output(7,4,∟CL(7
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,3,∟CL(7
:¦ ¦ End
:¦ ¦ If 10>∟CL(8
:¦ ¦ Then
:¦ ¦ ¦ Output(7,8,"0
:¦ ¦ ¦ Output(7,9,∟CL(8
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,8,∟CL(8
:¦ ¦ End
:¦ ¦ If 10>∟CL(9
:¦ ¦ Then
:¦ ¦ ¦ Output(7,12,"0
:¦ ¦ ¦ Output(7,13,∟CL(9
:¦ ¦ ¦ Else
:¦ ¦ ¦ Output(7,12,∟CL(9
:¦ ¦ End
I'm not sure If I'm right about this part or not, I'll let Kerm or someone else with experience judge it, but I don't think you need the "then" statements when you only have one IF statement in a IF loop followed by an ELSE like you have. I remember getting away with that before.
If not, I remember seeing this funky way of writing If/then statements without using IF or THEN at all, that way all's the calculator has to do is compute instead of running loops, I'll look into it and get back to you on that though.
You can skip the Then for an If followed by a single statement, but if you need an Else, I'm afraid you need to add the Then/End back in, even for single statements after the If and Else. Regarding the If statements without Ifs, consider:


Code:
If X=22
A+1->A

If X=23 or X=24
B+1->B

If X>389
C+1->C

If X=-1 or X=3
D+1->D


These can be respectively optimized:


Code:
A+(X=22->A
B+max(X-23={0,1->B
C+(X>389->C
D+(2 = abs(X-1->D
Okay, will make those changes (where applicable).

Kerm, if there's no way to optimize the If/Then statements, is there a way to bypass them completely (but keep the "0" in front of single digits so the 9 from the previous minute isn't displayed)?
Kerm's always on top of things Smile
Beta, Couldn't you just use an
Output(y,x,"0
Command at the beginning of the loop? Or will that not work?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement