hello!
As you can tell I am new to this board, but I hope that I may still be able to get my point across as I value everyones input!

Last week while I was being bored to death from my professor explaining how the color code for resistors work for the MILLIONTH TIME, I got thinking about creating a program on my TI-83 that would essentially give the color code for a resistor from the numerical value that you enter. It seemed simple enough, so I began the task. Once I started actually laying out the logic for it though, I soon realized this may not be as easy as I thought Sad
For those who are not familiar with how the resistor color code system works, essentially each resistor has 4 colored bands on it. The first band represents the 10's column number of the resistors value, the 2nd band represents the 1's column digit, the 3rd band represents that value that 10 gets raised to and multiplied against the number from the first 2 bands, and the 4th band states the acceptable tolerance limit for the resistor. Example, a resistor whos colored bands were orange, red, orange, and gold would have a value of 32K Ohms, the 1st orange band being the 3, the 2nd red band being the 2, giving a value of 32. This number is then raised by 10^3, with the 3 coming from the 3rd orange band.

The main plan of attack I had for this problem was to seperate a number like 32000 into 3 variables, X representing the 10's column, Y representing the 1's column, and Z representing the exponent of base 10. I would then compare these variables, and display their colors. (3 equals orange, 2 equals red and so on)

The first problem I ran into was figuring out how to get these 3 variables from one input prompt. After much head scratching I came up with a main idea.
Modulusly (sp? haha) divide the inputted number (32000 in this case) by 10^X, with X representing the base 10 value of the first number, in this case the ten thousands column, or 10^4)
using fpart(32000/10000)*10000 leaves me with the remainder of 2000, which i subtract from my original value of 32000, giving me 30,000 which I then mathematically divide by 10^4 again giving me 3. This gives me both the X and the Y that I am seeking, X from what I just explained and Y as you will see below. How do I get the Z value though! How will the calculator be able to know to divide 32,000 by 10,000 and 32,000,000 by 10,000,000?

Well I loosely came up with a For loop of sorts that would go as follows if written in C language

( int z = 0; z < 99; z++ )

//continuously mod divide the original number (32000) by 10, and as long as the remainder is equal to 0, add 1 to Z.
EX.
32000%10=3200=x, y=0, z=1
3200%10=320=x, y=0, z=2
320%10=32=x, y=0, z=3
32%10=3=x, y=2, z=4

This gives me z=4 (i think, or if it still remains as z=3 I can just alter the later formula), and I'll know that 10^(Z-1) multiplied by 32 gives me 32,000 and I'll be able to get the colors from that. If z=3 however, I can just multiply by 10^Z

My syntax however is what obviously needs some work Sad
Is this method even possible in TI-83's language?
If so I would GREATLY appreciate to understand how to call a recursive function such as this in the calculator.
If this works, I can simply just compare each value X,Y, and Z to some If statements which will give me the appropriate colors!

Example Output:

Value?= 32000
The colors are:
Orange, Red, Orange

I appreciate ANY and ALL feedback to this matter, ESPECIALLY any suggestions of a better way to solve this problem. Thank you for reading!
Welcome to Cemetech! I hope you enjoy your stay.

So the resistor color code (I have two degrees in EE, a bachelors and a masters, by the way) is indeed based on a multiplier. Say you use the following to input the resistor value in ohms:


Code:
Input "VALUE (OHMS):",X


You could then extract the three bands this way:

Quote:
X/10^(int(log(X->A
int(10fPart(A->B
int(A->A
int(log(.1X->C


This would yield A = first band, B = second band, and C = number of zeros (third band).
thanks for the reply!
would you mind explaining to me how this works?
MILLERRRR wrote:
thanks for the reply!
would you mind explaining to me how this works?
I'd be happy to. Lemme just throw it onto a calculator to make sure that the code in my head works as I expect it to.

Edit: Yup, all good. Aight, so say you get X = 3300 ohms. You would hope that A=3, B=3, and C=2, correct?

X/10^(int(log(X->A
Log of X is related to how many places it has in decimal. log(3300) is 3.518, so int(log(3300)) means take the log and round down: 3. Indeed, this tells us that X = 3.30*10^3. We divide X (3300) by 10^3, in this case, leaving us with 3.3. Notice how the 3. and the .3 are the two digits we want to extract. A=3.3

int(10fPart(A->B
Multiply the fractional part of A by 10, eg, 0.3*10 = 3, and round down (still 3 here). B=3.

int(A->A
A has to be an integer, so now we round down. A=3.

int(log(.1X->C
Because we have two integer places, 3300 is 3, 3, and 2 zeros. Log(X) = 3.5, and Log(.1X) is the same as Log(X)-1, so Log(.1X) here = 2.5. We round down, yielding C=2.

A=3, B=3, C=2
awesome, you really know your stuff! thanks alot
MILLERRRR wrote:
awesome, you really know your stuff! thanks alot
Thanks, I do my best. Smile So where do you plan to go with this? Are you going to make a nifty GUI? Do you want to know the best way to turn A, B, and C into color strings like "RED" instead of numbers?
I really have no knowledge of the ti-83 language other than what I found out just from playing around. No idea how to make a GUI lol. And I cant do strings b/c there are only 10 available placeholder but black-white = 10 colors plus gold and silver for that LAME 3rd band multiplier Sad So i was just going to do
if x=0
Disp "Black"
if x=1
Disp "Brown"
etc etc

Something tells me there is a better way though haha

I also have a program that goes backwards to this problem. A series of menus asks for the colors and then displays the value Very Happy
any ideas on making that cooler?
Sure, you should post it up. Do you have the cable to connect your calculator to your computer? If so, you can use SourceCoder to extract human-readable source code from .8xp file.


Code:
sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT GOLDSLVR",4C+1,4
This would yield "BLCK" for C=0, "GRN " for C=5, "WHT" for C=9, "GOLD" for C=10, "SLVR" for C=11, etc.
unfortunately i do not.
also sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT GOLDSLVR",4C+1,4 looks like gibberish to me haha

basically the code is
MENU("1st band", "black",10,"brown",11,"red",12 etc etc
lbl 10
0->X
goto lbl m3
lbl 11
1->x
goto lbl m3
etc etc

lbl m3
MENU("2ND band", "black",20,"brown",21,"red",22 etc etc
etc etc

then after you choose the 4th band it goes to the "computation" label, adds it all up and displays it, along with its +/- tolerance levels
the sub() means substring:

Example:

"Test String->Str1
Disp sub(Str1,2,5

This code would display:

est S

Syntax for the sub() function is : sub(<String>,<Start position>,<Length of string after sub position>

So in my code above, sub() took the the 5 letters of Str1 after the 2nd character in the string

Hope that made sense Smile

Edit; Whoa that is a lot of menus you are planning to make Surprised. You should use loops and lists to optimize that section of your code Surprised
That gibberish is just the colors, BLCK, BRWN, RED, ORNG, YLLW, GRN, BLUE, VLT, GRAY, WHT, GOLD, SLVR.

I think a better version would be like this:


Code:
prgmCLR2NUM
:ClrHome:Disp "FIRST BAND:
:prgmZGETBAND
:X->A
:ClrHome:Disp "SECOND BAND:
:prgmZGETBAND
:X->B
:ClrHome:Disp "THIRD BAND:
:prgmZGETBAND
:X->C
:Disp (10^C)(10A+B

prgm:ZGETBAND:
:0->X
:Repeat K=105
:Output(2,1,sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT ",4X+1,4
:X+(K=25 and X=/=9)-(K=34 and X->X
:End
I already made them, I had ALOT of time to kill haha

I have a very general sense of the ti83 programming so optimizing the code isnt a very fruitful process Very Happy
MILLERRRR wrote:
I already made them, I had ALOT of time to kill haha

I have a very general sense of the ti83 programming so optimizing the code isnt a very fruitful process Very Happy
Aww, but it's so much fun! You should really stick with it more. Does the code I posted above make sense?
You should not add unnecessary code like that, it will slow down the program and use up your memory. I can help you with optimizing that menu section of your code if you want, but not today *yawns*.
KermMartian wrote:


Code:

prgm:ZGETBAND:
:Delvar XRepeat K=105
:Output(2,1,sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT ",4X+1,4
:X+(K=25 and X=/=9)-(K=34 and X->X
:End

Couldn't help but optimize, shaved off two bytes Razz
KermMartian wrote:
That gibberish is just the colors, BLCK, BRWN, RED, ORNG, YLLW, GRN, BLUE, VLT, GRAY, WHT, GOLD, SLVR.

I think a better version would be like this:


Code:
prgmCLR2NUM
:ClrHome:Disp "FIRST BAND:
:prgmZGETBAND
:X->A
:ClrHome:Disp "SECOND BAND:
:prgmZGETBAND
:X->B
:ClrHome:Disp "THIRD BAND:
:prgmZGETBAND
:X->C
:Disp (10^C)(10A+B

prgm:ZGETBAND:
:0->X
:Repeat K=105
:Output(2,1,sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT ",4X+1,4
:X+(K=25 and X=/=9)-(K=34 and X->X
:End




The main code makes sense. The function ZGETBAND does not, care to explain? Confused

edit: Oh I see. I am not familiar with GUI capabilites of the program (shocking I know). Why does each color need to be 4 letter though? Is it possible to use the colors full length name?
TheStorm wrote:
KermMartian wrote:


Code:

prgm:ZGETBAND:
:Delvar XRepeat K=105
:Output(2,1,sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT ",4X+1,4
:X+(K=25 and X=/=9)-(K=34 and X->X
:End

Couldn't help but optimize, shaved off two bytes Razz
Thanks. Smile There were a few other optimizations that I see, but I wanted to make the code moderately understandable to a beginner. Smile

Edit: @Miller: the ZGETBAND program allows the user to press [up] and [down] to select the name of a color. When he or she presses enter, it returns the value of the color (0 through 9) in X.
MILLERRRR wrote:
unfortunately i do not.
also sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT GOLDSLVR",4C+1,4 looks like gibberish to me haha

basically the code is
MENU("1st band", "black",10,"brown",11,"red",12 etc etc
lbl 10
0->X
goto lbl m3
lbl 11
1->x
goto lbl m3
etc etc

lbl m3
MENU("2ND band", "black",20,"brown",21,"red",22 etc etc
etc etc

then after you choose the 4th band it goes to the "computation" label, adds it all up and displays it, along with its +/- tolerance levels


TheStorm, did you see how many unnecessary menus he made? It could shave probably 100-300 bytes if it was optimized.

Edit: Kerm, you could use a loop instead of a subprogram which would be better for the user (less programs)
souvik1997 wrote:
MILLERRRR wrote:
unfortunately i do not.
also sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT GOLDSLVR",4C+1,4 looks like gibberish to me haha

basically the code is
MENU("1st band", "black",10,"brown",11,"red",12 etc etc
lbl 10
0->X
goto lbl m3
lbl 11
1->x
goto lbl m3
etc etc

lbl m3
MENU("2ND band", "black",20,"brown",21,"red",22 etc etc
etc etc

then after you choose the 4th band it goes to the "computation" label, adds it all up and displays it, along with its +/- tolerance levels


TheStorm, did you see how many unnecessary menus he made? It could shave probably 100-300 bytes if it was optimized.

Edit: Kerm, you could use a loop instead of a subprogram which would be better for the user (less programs)
I absolutely would prefer that, and store A, B, and C in a list, but I wanted to ease him into that. Smile
souvik1997 wrote:
MILLERRRR wrote:
unfortunately i do not.
also sub("BLCKBRWNRED ORNGYLLWGRN BLUEVLT GRAYWHT GOLDSLVR",4C+1,4 looks like gibberish to me haha

basically the code is
MENU("1st band", "black",10,"brown",11,"red",12 etc etc
lbl 10
0->X
goto lbl m3
lbl 11
1->x
goto lbl m3
etc etc

lbl m3
MENU("2ND band", "black",20,"brown",21,"red",22 etc etc
etc etc

then after you choose the 4th band it goes to the "computation" label, adds it all up and displays it, along with its +/- tolerance levels


TheStorm, did you see how many unnecessary menus he made? It could shave probably 100-300 bytes if it was optimized.

Edit: Kerm, you could use a loop instead of a subprogram which would be better for the user (less programs)



1250 bytes total haha
  
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 3
» 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