Author Topic: zhuravsky DIP switch with binary value  (Read 8791 times)

0 Members and 1 Guest are viewing this topic.

michdan

  • Newbie
  • *
  • Posts: 6
zhuravsky DIP switch with binary value
« on: October 30, 2014, 02:05:54 AM »
Hello

In a previous thread, zhuravsky modified a DIP switch so that all you needed to do was to move the PIN to the ON or OFF position in order to set it.

http://visguy.com/vgforum/index.php?topic=711.msg3193#msg3193

Is it possible to somehow show the binary value that the dip switches represent as a number?

For example:
If I set the dip switch 1 to ON and the others switches to OFF I will have the value 1.
If I set the dip switch 1 and 3 to ON and the others switches to OFF I will have the value 5 and so on

/michael

Yacine

  • Hero Member
  • *****
  • Posts: 2712
Re: zhuravsky DIP switch with binary value
« Reply #1 on: October 30, 2014, 02:30:12 PM »
Hello Michael,
a value for the switch can be displayed.
To answer you question, I added a user field to the shape that reads out the state of the individual switches and put the result in the shape text.
The text displayed is probably not yet exactly what you need, but at least it shows how this can be done.
« Last Edit: October 30, 2014, 02:33:04 PM by Yacine »
Yacine

michdan

  • Newbie
  • *
  • Posts: 6
Re: zhuravsky DIP switch with binary value
« Reply #2 on: October 31, 2014, 03:05:38 PM »
Hello yacine
Thanks for your response, I will see if I can somehow convert the positions into a decimal value.

Regards
Michael

Yacine

  • Hero Member
  • *****
  • Posts: 2712
Re: zhuravsky DIP switch with binary value
« Reply #3 on: October 31, 2014, 04:19:56 PM »
Download the VSD.
Yacine

michdan

  • Newbie
  • *
  • Posts: 6
Re: zhuravsky DIP switch with binary value
« Reply #4 on: November 04, 2014, 12:12:15 PM »
Hello Yacine

I have downloaded your stencil, but I can not figure out how the position of the dip switch is being convertet into a '0' or '1'.

Is it a text box figure where you write your '0' and '1' ?

Could you explain in small steps how you made this?

I am totally newbie in shapesheets so any help is appreciated  :D

/michael

Yacine

  • Hero Member
  • *****
  • Posts: 2712
Re: zhuravsky DIP switch with binary value
« Reply #5 on: November 04, 2014, 01:19:24 PM »
Hi Michael,
  • there is no other field holding the value of the switch than the position of the control points (That's the "controls.row_1 to 12" and the .Y /vertical value of it)
  • Then I looked for the possible values of this field. In this case it it 0.6563 in or 1.0313. So if the value is greater than 1 = the switch is on, otherwise it is off
  • I translated this in the formula: "IF(Controls.Row_1.Y<1 in,0,1)". (This is the same as If ... then ... else ...
  • Then I concatenated all the columns by means of an "&" sign. IF(Controls.Row_1.Y<1 in,0,1)&IF(Controls.Row_2.Y<1 in,0,1)&IF(Controls.Row_3.Y<1 in,0,1)&IF(Controls.Row_4.Y<1 in,0,1)&...
  • This field is the placed in the text of the shape (menu insert/field/user/Row_13
Hope this is clear enough.
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #6 on: November 04, 2014, 01:56:31 PM »
To convert to decimal you need to do to things to Yacine's formula in User.Row_13:
  1:  Change the "&" to "+"
  2:  Substitute the decimal equivalent value for each "1".  For example, at the far right of the formula, if switch 12 is high, value is "1" for both binary or decimal, but, for switch11 the "1" becomes a "2", the decimal value for binary binary position, and, switch10, the "1" converts to "4", etc.

That ought to do it.

Some options:  (1) Leave Row_13 formula unchanged, add a Row_14, copy formula, modify as above, and you have both binary and decimal available
                        (2) Using Insert field, change to custom formula to be =User.Row_13&CHAR(10)&"("&User.Row_14&")"  or enter directly in the shapesheet Text Fields section, in the value cell.  This will display both the binary and the decimal values.

HTH

Wapperdude
 
« Last Edit: November 04, 2014, 02:24:59 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #7 on: November 04, 2014, 04:59:29 PM »
Oh, one other point of interest, normal binary is presented in groups of four digits, so, the row_13 formula could be modified to have a & " " & between the IF statements rather than the single "&" between the 4th & 5th and the 8th & 9th IF statements.

Wapp
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2712
Re: zhuravsky DIP switch with binary value
« Reply #8 on: November 05, 2014, 12:27:16 PM »
Hi Michael and Wapp,
I felt bored and played a little bit with the shape.
Use the new control points and let me know what you think about.
Yacine

michdan

  • Newbie
  • *
  • Posts: 6
Re: zhuravsky DIP switch with binary value
« Reply #9 on: November 05, 2014, 12:54:09 PM »
Hello Yacine

That was exactly what I was looking for, this is really nice.

I really have to work some more with this shapesheet programming :-)

Do you know any good books, websites, documentation etc. that can help a newbie like me to get started with understanding shapesheet programming?


/michael

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #10 on: November 05, 2014, 01:19:57 PM »
@Yacine:  Yeah, that's basically it.  The only changes I'd suggest are the following:
  1.)  In binary, the reading goes from right to left, not left to right.  So, your binary word needs to be flipped.  You had it correct with your original reply.  Actually, decimal is the same way, right to left: 1's, 10's, 100's, 1000's, etc.
  2.)  How a user places the switches if somewhat arbitrary, but it would be less confusing if they also followed the conventional binary pattern.
  4.)  The trunk left is a nice feature.
  5.)  The switch identifier is nice
  5.)  I would still recommend adding the "space" every fourth digit, as that is also convention (well, mostly.  Does improve readability)
  6.)  The number of digits seems unnecessary, perhaps should be a displayable option
  7.)  Another possible option is to use the actions menu to let user select what's displayed:  binary, decimal, or both.  That's probably overkill at this point.
 

I had updated your original post to contain the my original modifications, I'll put it here, now, to illustrate what I mean.  Does not contain your enhancements.

Wapperdude
« Last Edit: November 05, 2014, 01:29:35 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #11 on: November 09, 2014, 08:18:58 PM »
Major update to the zhuravsky DIP switch:
  1.)  Switches and binary digits are in correct right to left order
  2.)  Switch designator is shape data entry
  3.)  Binary digits are arranged in groups of 4.
  4.)  Binary and decimal values only represent number of switches shown.  Non-visible switches do not contribute to the binary and decimal values.
  5.)  Binary now truncs right, not left.

Wapperdude
« Last Edit: November 09, 2014, 08:22:12 PM by wapperdude »
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2712
Re: zhuravsky DIP switch with binary value
« Reply #12 on: November 10, 2014, 02:30:38 AM »
@Wapperdude, nice job.
Getting the value by "Controls.Row_1.Y>1 in" is however risky. If the main shape is too small, the formula interprets FALSE, where it should be TRUE.
Better would be to use a variable.
Cheers,
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #13 on: November 10, 2014, 05:22:05 AM »
@Yacine:  You're absolutely right.  I was trying to keep the concept and implementation as close as possible to the original, and didn't think about the 1" issue.  The correct solution to allow better scaling, is to replace the "1 in."  with a height relative value, namely, "height*0.63".  With that change, then the size is not important.  But, the entire shape doesn't scale very well because the text isn't setup to scale.  In addition, at very small sizes, the line weight becomes an issue too.

Thanks for catching that though, there wasn't much margin at all!

Wapperdude
« Last Edit: November 10, 2014, 05:23:36 AM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: zhuravsky DIP switch with binary value
« Reply #14 on: November 10, 2014, 12:04:42 PM »
Updated: 
  1.  Fixed the controls value reference.   ???
  2.  Re-paired the text scaling that I had unintentionally disabled.   :o
  3.  Added some "group" coloring to the switches to make it a little more obvious what the physical groups of four are.   ::)

Wapperdude
« Last Edit: November 10, 2014, 04:03:48 PM by wapperdude »
Visio 2019 Pro