March 18, 2024, 11:17:14 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Resistor Colour Codes

Started by GWS, June 21, 2013, 09:46:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

June 21, 2013, 09:46:59 PM Last Edit: June 26, 2013, 05:51:57 AM by GWS
Hi folks,

This little program started out as a simple look-up table - but just grew to be more ambitious ..  ::)

It can now be used in three ways:

- as a look-up table, or
- if you have an existing resistor, you can set the band colours, and it's value in ohms will be displayed, or
- if you have a particular value in mind, you can enter the value, and the band colours will be displayed.

It has the preferred values for the E12, E24, E48, E96, and E192 series built in.

Only of interest for electronics dabblers like myself I suppose, but 'interesting' to code.  :P

I was much helped by the Creative Debug facilities, which, with judiciously inserted STOP commands, allowed me to see the contents of all variables at that point.

This helped find all sorts of logic errors - to which I am prone ..  ;D

Anyway, I hope you find it useful ..

Best wishes, :)

Graham

[Modified the program to correct a bug found by Bill ..  :)]
[Extended the program to handle values less than 1 ohm for 5-band resistors]
Tomorrow may be too late ..

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Thanks Larry ..  :)

I hope my programs may interest people in what can be done with Basic in general, and Creative in particular.

Over the years, so many different applications have been developed by many users with this simple language. Folk only have to look back in the Forum archives to see what has been achieved.

I wish I'd had Creative available when I was what they term 'economically active' ..  ::)

I could have made management's eyes pop out .. all the programs I worked on in Fortran for so many years, could have been developed more efficiently, and as considerably better tools, using Creative rather than Fortran on the IBM 370's we had to work with.

This language is capable of so many things ..

All the best, :)

Graham
Tomorrow may be too late ..

billhsln

When all else fails, get a bigger hammer.

GWS

June 23, 2013, 02:34:58 AM #4 Last Edit: June 23, 2013, 05:50:56 AM by GWS
Thanks Bill .. it made me scratch my head at times ..  ;D

All the best, :)

Graham
Tomorrow may be too late ..

Bill-Bo

Graham,

This is a GREAT program. I do have an issue about it.
If you could work into your display window the 'Preferred
Value' in a box to the right of 'Enter'. Stupid me, when
I first ran it, I thought the popup was an error window
indicating I was entering my 4700 Kilo ohms wrong. Then
I figured out that's the 'preferred' way it's to be written.

Again, a GREAT!! program,

Bill

GWS

Hi Bill,

Oh no! .. you've found another bug - I had hoped I'd squashed them all .. ::)

If you enter 470 Kohms in the top edit box, you get the correct colours, and preferred value information box.

If you enter 4.7 Mohms, you get the correct colours, but the wrong preferred value information  - it currently says 4.7 Kohms is the preferred value - which is wrong.

If you enter 4700 Kohms, you get the wrong colours and the wrong message  :o ..

Oh well .. back to the drawing board .. I'll see if I can spot what's happening.
There are so many ways the user data entry can trip you up in this program.

"I'll be back" as Mr Schwarzenegger says .. it might take a while ..

all the best, :)

Graham


Tomorrow may be too late ..

Bill-Bo

Graham,

Well, I'm kind-of glad I used that value for a test. It
was a common value in my circuit building days.

Bill

GWS

Phew,

I think I found what was wrong .. I've corrected the program and re-posted the .zip file in the first post.

I hope I haven't upset something else by making the changes ..  ::) .. always a danger in a complex program.

On your main point Bill, I did consider putting the preferred values in a separate box, but as always the screen real estate is limited.  So I settled for using a pop-up information message box.

I hope it will work now.  Time for bed .. I'll do some more checking tomorrow.

Best wishes, :)

Graham
Tomorrow may be too late ..

GWS

June 24, 2013, 02:16:16 AM #9 Last Edit: June 24, 2013, 05:43:46 AM by GWS
Hi folks,

Sorry, this seems to have gone pear shaped again - I was afraid of that.

The user interface is very active, and making it work consistently is hair raising ..

The difficulty is mostly found in the two subroutines Enter1 and Enter2, which handle whatever the user types into the edit boxes for the upper 4 band, and lower 5 band resistors.

A lot is going on here.

The setting of the units scrollbar needs to be taken into account. (so for example, an entry of 0.5378 for the top resistor - together with a Kohms scrollbar selection - becomes a value of 537.8 ohms in variable res1.

It just gets trickier from then on ..  ::) as the value needs to be rounded to two digits, because a 4-band resistor can only specify two digits and a multiplier.

Then you have to pick out these two digits (in variable b$) and find the preferred value using the Pref2() function.

These are used to set the band colours, together with a mutliplier band colour, which is set using 'm = log10(mult)'.

So, I'll just have to work through it again to find where it's all going wrong. ::)
If anyone else can tame it, that would be great ..  ;D  Isn't programming fun ?  ;D ;D

I'll take the above version down while I try to find what's going on .. ::).

Might take a while, I've got an appointment this morning.

Best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Hi folks,

I think I've sorted the program out now ..  :)

I've broken down the Enter routines into smaller subroutines, and added the capability to deal with values less than 1 ohm for 5-band resistors.  (Most on-line programs won't handle this).

Hope it works now ..  ::)

Best wishes, :)

Graham
Tomorrow may be too late ..

GWS

OK .. one last change  .. I hope  ::)  Updated above. ;D

Hopefully, unless they tried something unusual, nobody would have spotted the snag.

If you set the band colours of the lower 5-band resistor to say Brown, Red, Orange, Red - giving a value of 12.3Kohms - if you now set the Band 1 colour to Black, an error occurred  :o

I've corrected this now, so that setting Band 1 to Black resets the other band colours, and enforces Silver for Band 4.  This is because setting Band 1 to Black is only valid for values of less than 1 ohm.

I think it's finished now - it was a tricky little project.

On to the next .. so much to do ..

Best wishes, :)

Graham
Tomorrow may be too late ..

Brian

Hi, converted Graham's program to run on IWB, if anyone is interested

Brian

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Yes, I met him a couple of times in the PT days. A very mild-mannered, lovely gentleman, and quite clever with it, as well. I miss the odd electronic 'chats' we used to have

Brian