Scaling analog values

482 views
Skip to first unread message

Eric Williams

unread,
Feb 3, 2014, 5:23:25 PM2/3/14
to comman...@googlegroups.com
I'm using the Crestron Mobile V3.4 with a particular gui.  I have a 16bit analog value coming in (volume gauge). I would like this to be displayed as a percentage 0-100% on a serial join.  I already have a function triggering when the join changes that uses parseInt to return a value.  Is there a easy way to simply convert that into a percentage?  


**Please include as much software version information as possible. This ensures that other users and CommandFusion staff can provide a helpful answer as quickly as possible.** - Please Delete this line BEFORE posting.

Barry Gordon

unread,
Feb 3, 2014, 6:17:43 PM2/3/14
to comman...@googlegroups.com
Mathematically it's is trivial and would be so in Javascript. Take whatever value you have and divide it by the maximum value it can achieve. That produces a fraction ranging from 0 to 1. Multiply that by 100 and you have the percentage you want.

Sent from my iPad

On Feb 3, 2014, at 5:23 PM, Eric Williams <ewilli...@gmail.com> wrote:

I'm using the Crestron Mobile V3.4 with a particular gui.  I have a 16bit analog value coming in (volume gauge). I would like this to be displayed as a percentage 0-100% on a serial join.  I already have a function triggering when the join changes that uses parseInt to return a value.  Is there a easy way to simply convert that into a percentage?  


**Please include as much software version information as possible. This ensures that other users and CommandFusion staff can provide a helpful answer as quickly as possible.** - Please Delete this line BEFORE posting.

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Eric Williams

unread,
Feb 3, 2014, 6:38:28 PM2/3/14
to comman...@googlegroups.com
Damn, that was way too obvious, I think I've been working to much...
 
thanks,

Barry Gordon

unread,
Feb 3, 2014, 6:54:32 PM2/3/14
to comman...@googlegroups.com
After you have done 20 or so sliders it kind of becomes ingrained.

Sent from my iPad
--

Kol Johnson

unread,
Feb 4, 2014, 11:37:30 AM2/4/14
to comman...@googlegroups.com
You can do the translation in Simpl (divmod) then you will only be sending 100 possible values to CF instead of 65536.

Barry Gordon

unread,
Feb 4, 2014, 11:55:41 AM2/4/14
to comman...@googlegroups.com

It depends on what you want to do with the value once you get it.  If you want to use the value to control a slider then you need to scale it to be 0-65535. If you want to show it as a percentage you need it to be scaled 0-100.

 

I do both for my lighting system. My lighting system returns 0-100 so I only need to scale it for a slider.  (divide by 100, multiply by 65535 or just multiply by 655.35)

 

The volume return from my A/V system is more complex.  It returns a value from -80 to +20. In that case two things need to be done. First the origin needs to be reset by adding 80 to the returned value producing a value in the range 0-100.  The value can then be divided by 100 to produce a fractional value in the range 0-1.  In Javascript all arithmetic is handles internally in floating point so the system is more accurate than needed for the display of volumes and we need not worry about rounding errors.

Reply all
Reply to author
Forward
0 new messages