Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: theuserofallusers on December 21, 2013, 08:16:03 pm

Title: basic clock program for ti 84 plus
Post by: theuserofallusers on December 21, 2013, 08:16:03 pm
:ClrHome
:Lbl 1
:For(X,3,16)
:Output(4,X,"<what ever you want>
:For(Y,5,20)
:Output(7,Y,getTime
:Goto 1
:ClrHome

The code makes a loop that updates every time the getTime is displayed,this only shows for about 20-30 seconds and to exit it press the on button.
Title: Re: basic clock program for any ti caclulator
Post by: DJ Omnimaga on December 21, 2013, 08:44:36 pm
Nice implerrmemtation of a clock.
Title: Re: basic clock program for any ti caclulator
Post by: theuserofallusers on December 21, 2013, 09:03:42 pm
Thanks I just got bored in math class and screwed around with the programs....and boom there it is
I need some help to create a more complex one so anyonencan help me, because right now I'm  :banghead:
Title: Re: basic clock program for any ti caclulator
Post by: Hexatron on December 21, 2013, 09:39:40 pm
You could use the formula for a circle : (x−h)2+(y−k)2=r2 to draw a line from the center of the graph to the edge of a circle (if that formula i just copypasted works the way I think it does) to represent the current time in (UNITS / 60) / 360.
Title: Re: basic clock program for any ti caclulator
Post by: fb39ca4 on December 21, 2013, 09:48:45 pm
What is the purpose of the for loops?

Hexatron: For drawing a line representing the hands of a clock? The implicit equation for a circle would not be helpful in that case. You want the starting and ending point for the line drawing command. The starting point is the center of the circle, and the end is at some point on the edge of the circle at the particular angle. You can use trig to calculate that ending point.
Title: Re: basic clock program for any ti caclulator
Post by: DJ Omnimaga on December 21, 2013, 09:48:56 pm
Thanks I just got bored in math class and screwed around with the programs....and boom there it is
I need some help to create a more complex one so anyonencan help me, because right now I'm  :banghead:
Well, to start off, you would obviously need to remove memory leaks. In your program, for example, the two For instructions are unnecessary because you are already looping through Lbl and Goto and Goto-ing from a For/While/Repeat/If block is what causes the memory leak  and error. Even then, While 1:End would be better than Lbl 1-Goto 1 because if the Lbl is lower in the code, then it's much slower to loop than anything else.
Title: Re: basic clock program for any ti caclulator
Post by: theuserofallusers on December 21, 2013, 11:46:08 pm
Ill try it later but thanks for all the help I will post my progress when I'm done, btw I'm trying to find a simple basic ti-85 program that displays a bouncing "ball" on the screen any help with that?
Title: Re: basic clock program for any ti caclulator
Post by: DJ Omnimaga on December 22, 2013, 12:56:35 am
Unfortunately, since the TI-85 has been discontinued in 1997 (before most forum members were even born), there are very few TI-85 owners anymore in the TI community, but its Basic language is pretty similar in general to the TI-84 Plus, so hopefully if you search the forums or Google you might be able to find something helpful. TI-Basic Developer can also help, although it's for the 83+/84+.
Title: Re: basic clock program for any ti caclulator
Post by: theuserofallusers on December 22, 2013, 01:29:56 am
Wow I did not know that the reason I ask I because I'm going to start a new semester and I was going through my electronics box (I know Nerdy) and found my old ti-85 and I thought well I wounded. Thanks for the help, I'll go and google.
Title: Re: basic clock program for any ti caclulator
Post by: ben_g on December 22, 2013, 07:40:13 am
This post is not meant to demotivate you, but I think that it's best to avoid these mistakes when you start making more complex programs.

:ClrHome
:Lbl 1
:For(X,3,16)
:Output(4,X,"<what ever you want>
:For(Y,5,20)
:Output(7,Y,getTime
:Goto 1
:ClrHome

The code makes a loop that updates every time the getTime is displayed,this only shows for about 20-30 seconds and to exit it press the on button.
For loops should be closed by an end. Goto can be used to form a loop, but using a goto to go out of a loop is usually a bad idea. iirc it can even cause a memory leak.

This is how for loops usually work:
Code: [Select]
:For(<variable>,<start>,<end>)
:<do something>
:End
<variable> is a real variable (=uppercase character or one of the variables from the finance app).
At the start of the loop, that variable is set to the <start> value. Then, the code inside the loop is executed. If the variable is smaller than the <end> value, it gets incremented (1 is added to it), and the code in the loop is executed again. This keeps happening untill the variable is greater than or equal to the <end> value.

An other thing that seems slightely inaccurate is that you say in the title that it works on any ti calculator. This is most lickely not true. The lay-out of this code looks like basic for the z80 line (83+/84+ lines), and not all calculators in that line have a clock, so GetTime won't work on all of those calculators (iirc only on the 84+ line (84+, 84+SE and probably also the 84+CSE)).

Anyway, if anything is unclear, feel free to ask about it. This forum has a lot of helpfull members.
Title: Re: basic clock program for any ti caclulator
Post by: theuserofallusers on January 22, 2014, 08:58:59 pm
Thanks that helps, I will post a revised version later
Title: Re: basic clock program for any ti caclulator
Post by: calcdude84se on January 22, 2014, 09:40:28 pm
This is how for loops usually work:
Code: [Select]
:For(<variable>,<start>,<end>)
:<do something>
:End
<variable> is a real variable (=uppercase character or one of the variables from the finance app).
At the start of the loop, that variable is set to the <start> value. Then, the code inside the loop is executed. If the variable is smaller than the <end> value, it gets incremented (1 is added to it), and the code in the loop is executed again. This keeps happening untill the variable is greater than or equal to the <end> value.
TI-BASIC for-loops work slightly differently. (I say after verifying this to make sure I wouldn't make an idiot of myself by incorrectly correcting you x.x)
Namely, when <do something> is finished, first <variable> is incremented, and then if it is less than or equal to <end>, <do something> gets executed again. Only when the incremented <variable> is greater than <end> does the loop end.
Admittedly, this only produces different results in two ways. It loops floor(<end>-<start>)+1 instead of ceil(<end>-<start>)+1 times, which only matters when <end>-<start> is not integral. And <variable> ends up being floor(<end>-<start>)+<start>+1 (equal to floor(<end>)+1 when <start> is integral, and <end>+1 when both are), not ceil(<end>-<start>)+<start> (equal to ceil(<end>) when <start> is integral, and <end> when both are).
TL;DR: for the most common use (<start> and <end> integral, <end> >= <start>), the main difference is that <variable> ends up as <end>+1, not <end>.
(This is likely more detail than is important, and hopefully it's not too confusing to anyone, but it's nice to set the record straight. Naturally, no offense meant to you, ben_g :))
Also, as a reference to UoaU and others who want to read the whole thing and might be slightly confused: ceil/ceiling rounds up to the nearest integer (so ceil(-1.3)=-1, ceil(3)=3, and ceil(4.2)=5) and floor rounds down to the nearest integer (so floor(-1.3)=-2, floor(3)=3, and floor(4.2)=4). An integer is a number without a fractional part (ceil and floor leave these alone).
Title: Re: basic clock program for any ti caclulator
Post by: The_King on January 22, 2014, 09:41:48 pm
note this does not work for nspire series so technically not all ti calculators
Title: Re: basic clock program for any ti caclulator
Post by: calcdude84se on January 22, 2014, 09:47:57 pm
note this does not work for nspire series so technically not all ti calculators
While we're being technical, it should work for the 84+SE emulator that's on some Nspires ;). (Though you could argue it's not an Nspire anymore :P)
Edit:
Thanks that helps, I will post a revised version later
Good luck! I'm sure someone will be able to help you more at that point if you have any questions :)
Title: Re: basic clock program for any ti caclulator
Post by: The_King on January 22, 2014, 10:02:10 pm
note this does not work for nspire series so technically not all ti calculators
While we're being technical, it should work for the 84+SE emulator that's on some Nspires ;). (Though you could argue it's not an Nspire anymore :P)

however i am having trouble getting a rom for 84 se since wabbitemu for mac does not provide the rom automatically
if u can tell me a way that would be awesome
Title: Re: basic clock program for any ti caclulator
Post by: calcdude84se on January 22, 2014, 10:43:39 pm
note this does not work for nspire series so technically not all ti calculators
While we're being technical, it should work for the 84+SE emulator that's on some Nspires ;). (Though you could argue it's not an Nspire anymore :P)

however i am having trouble getting a rom for 84 se since wabbitemu for mac does not provide the rom automatically
if u can tell me a way that would be awesome

Well, the emulator I mention is built into the Nspire OSes that have them (and is activated when you swap the keyboards).
If the Mac version of WabbitEmu is anything like the others, when you start it up for the first time (or if you find it again in the menus) it should show a dialog providing you several ways to get a ROM. By far the easiest if you don't already have one is to use the FOSS bootcode and download the OS from the internet.
Also, to avoid derailing this topic, I'd recommend creating another topic if you have any further questions.
Title: Re: basic clock program for any ti caclulator
Post by: The_King on January 22, 2014, 11:14:24 pm
oh yeah i was thinking of the cx emulator :P
Title: Re: basic clock program for any ti caclulator
Post by: rocketTim on January 31, 2014, 10:07:39 am
In the past, I've programmed a clock using a sort of conversion rate to make the time graph hands on the graphing area using a line, with the x and y coordinates of the end of the hands being the cos(x) and sin(x) respectively. The entire clock is based on the unit circle.
Title: Re: basic clock program for any ti caclulator
Post by: Ti-newb on April 17, 2014, 02:43:08 am
Well, i haven't coded for the Ti-84 in a long time, but here i go :DDD


I've always wanted to try this but i guess in the past i failed. Gave it a try now and I think this'll work: (Il go test bugs soon)

I'll do some comments with "//" to explain my code
So anything after the //THIS IS A COMMENT and should not be included in the code


EDIT1: Changed the code, should be working now. maybe i'll go make it more pretty later ;D

[/code]
Code: [Select]


ClrHome


5 -> A  //length of Hour hand (in pixels), you may adjust these numbers if you want
7 -> B   //length of Minute Hand
25 -> C  //length of Seconds Hands


DelVar D
DelVar E
DelVar I
DelVar J
DelVar N
DelVar O
DelVar Z


Circle(48,32,C+1)     //setting up the circle encompass your second hand + 1 pixel


while(getKey != 45) //press CLEAR to stop program


getTime -> L1          //puts the time in a list, L1(1) holds hour, L1(2) holds Minutes, L1(3) holds Seconds


L1(3) -> S
Line(48+D*B,32+E*B,48+D*C,32+E*C,0)        //The second hand would erase the Hour and Minute hands if ever ontop of them
cos(S*6)->E                                                     // And i didnt want to update everything everytime
sin(S*6)->D                                                     //So i just made my Seconds Hand exist starting from the endpoint of Minutes Hand                                                     
Line(48+D*B,32+E*B,48+D*C,32+E*C)


  if(S = 0 or Z = 0)                                           //Only update when Seconds reaches zero
  Then
   L1(2) -> M                                               //Minute Hand
   Line(48,32,48+I*B,32+J*B,0)
   cos(M*6)->J                                             //Calculating Position. I,J I being my X-coordinate and J being Y-coordinate
   sin(M*6)->I
   Line(48,32,48+I*B,32+J*B)
   
   L1(1) -> H                                               //Hour Hand
   Line(48,32,48+N*A,32+O*A,0)
   cos(H*15)->O                                         //Calculating Position (24 hour assumed) N being X, O being Y
   sin(H*15)->N
   Line(48,32,48+N*A,32+O*A)
   
   1->Z                                                        //Variable so Minute and Hour are updated upon start-up
  End


End

Title: Re: basic clock program for any ti caclulator
Post by: theuserofallusers on August 25, 2014, 11:54:14 am
hey i have tried your code but it did not work all it does is draw a circle
Title: Re: basic clock program for any ti caclulator
Post by: Princetonlion.tibd on August 25, 2014, 02:01:08 pm
:ClrHome
:Lbl 1
:For(X,3,16)
:Output(4,X,"<what ever you want>
:For(Y,5,20)
:Output(7,Y,getTime
:Goto 1
:ClrHome

The code makes a loop that updates every time the getTime is displayed,this only shows for about 20-30 seconds and to exit it press the on button.
I don't think it works with the 83+'s. No gettime :P
Title: Re: basic clock program for ti 84 plus
Post by: theuserofallusers on August 27, 2014, 02:31:43 pm
yea changed the title its good  :w00t: