Discussion forum for the BasicX family of microcontroller chips.
Variable Conversion BX-24 - gouardopatrick - Feb 17 19:27:31 2009
Hello Everybody,
In my program top read a current, I have declared the following:
Dim I1 as Single
Dim V1Max as Single
And them I do something like that:
I1=V1Max / 0.031
Debug.Print "V1Max = "; CStr(V1Max);" "; "I1 = ";CStr(I1)
The result on my PC is a value of for example I1 = 9,23456
How can I modify to read only 9,2 , only one decimal which is more
than enough.
My intention later is to compare I1 in a conditional statement like
If I1 >20 then Switch off Radiator 1 using X10 command
If I1 >25 then Switch off Radiator 2 using X10 command
I may also send the current of each phase and Neutral to an LCD
display to read in real time the consumed current.
Thanks and Best Regards.
Patrick.
------------------------------------
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.
(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Variable Conversion BX-24 - David Sousa Mendes - Feb 18 3:20:43 2009
You can always do it the hard way:
I1=9.23456
Multiply it by 10:
I1=92.3456
Get only the integer part
dim Int_i as integer
Int_i=Int (I1)
and you are done
David
----- Original Message -----
From: gouardopatrick
To: b...@yahoogroups.com
Sent: Tuesday, February 17, 2009 11:27 PM
Subject: [BasicX] Variable Conversion BX-24
Hello Everybody,
In my program top read a current, I have declared the following:
Dim I1 as Single
Dim V1Max as Single
And them I do something like that:
I1=V1Max / 0.031
Debug.Print "V1Max = "; CStr(V1Max);" "; "I1 = ";CStr(I1)
The result on my PC is a value of for example I1 = 9,23456
How can I modify to read only 9,2 , only one decimal which is more
than enough.
My intention later is to compare I1 in a conditional statement like
If I1 >20 then Switch off Radiator 1 using X10 command
If I1 >25 then Switch off Radiator 2 using X10 command
I may also send the current of each phase and Neutral to an LCD
display to read in real time the consumed current.
Thanks and Best Regards.
Patrick.
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Variable Conversion BX-24 - Olle Bengtsson - Feb 18 12:21:00 2009
Hello Patrick
How about converting the vars to Byte and simplify 0.031 with 0.03?
The result could then be I1 = V1/0.03 = V1*33 (NOTE that V1/0.03 is ot
allowed!!)
That would give you a result like '9' which is from what you say
enough ... )
Best regards
/Olle
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Variable Conversion BX-24 - Olle Bengtsson - Feb 18 12:21:23 2009
Hello Patrick
How about redelcare the vars as Byte, simplify 0.031 with 0.03 and
make I1 = V1/0.03 = V1*33 (NOTE that V1/0.03 is not allowed!)
That would give a value of '9' which is from what you say just
enough .... ?
Regards
Olle
--- In b...@yahoogroups.com, "gouardopatrick"
wrote:
>
> Hello Everybody,
>
> In my program top read a current, I have declared the following:
>
> Dim I1 as Single
> Dim V1Max as Single
>
> And them I do something like that:
>
> I1=V1Max / 0.031
> Debug.Print "V1Max = "; CStr(V1Max);" "; "I1 = ";CStr(I1)
>
> The result on my PC is a value of for example I1 = 9,23456
>
> How can I modify to read only 9,2 , only one decimal which is more
> than enough.
>
> My intention later is to compare I1 in a conditional statement like
> If I1 >20 then Switch off Radiator 1 using X10 command
> If I1 >25 then Switch off Radiator 2 using X10 command
>
> I may also send the current of each phase and Neutral to an LCD
> display to read in real time the consumed current.
>
> Thanks and Best Regards.
>
> Patrick.
>
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )Re: Re: Variable Conversion BX-24 - rosa...@aol.com - Feb 18 13:13:12 2009
Hi,
Why you don't use the Fix command
dim y1 as single
dim y2 as single
y1 =9.932323
y2=fix(y1)
y2=9
or
dim y1 as single
dim y2 as integer
y1 =9.56000
y2=cint(y1)
y2=10
y1=9.22323
y2=cint(y1)
y2=9
cint will round value if the decimal is .5 or higher
rosarite
-----Original Message-----
From: Olle Bengtsson
To: b...@yahoogroups.com
Sent: Wed, 18 Feb 2009 1:12 am
Subject: [BasicX] Re: Variable Conversion BX-24
Hello Patrick
How about redelcare the vars as Byte, simplify 0.031 with 0.03 and
make I1 = V1/0.03 = V1*33 (NOTE that V1/0.03 is not allowed!)
That would give a value of '9' which is from what you say just
enough .... ?
Regards
Olle
--- In b...@yahoogroups.com, "gouardopatrick"
wrote:
>
> Hello Everybody,
>
> In my program top read a current, I have declared the following:
>
> Dim I1 as Single
> Dim V1Max as Single
>
> And them I do something like that:
>
> I1=V1Max / 0.031
> Debug.Print "V1Max = "; CStr(V1Max);" "; "I1 = ";CStr(I1)
>
> The result on my PC is a value of for example I1 = 9,23456
>
> How can I modify to read only 9,2 , only one decimal which is more
> than enough.
>
> My intention later is to compare I1 in a conditional statement like
> If I1 >20 then Switch off Radiator 1 using X10 command
> If I1 >25 then Switch off Radiator 2 using X10 command
>
> I may also send the current of each phase and Neutral to an LCD
> display to read in real time the consumed current.
>
> Thanks and Best Regards.
>
> Patrick.
>
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )Re: Re: Variable Conversion BX-24 - "ese...@" - Feb 18 13:39:19 2009
Hello Olle,
I don't understand your statement, "(NOTE that V1/0.031 is
not allowed!)".
Dividing a floating point variable (single) by a floating point
constant (single) seems to work on my BX-24?
Eric
----- Original Message -----
From: Olle Bengtsson
To: b...@yahoogroups.com
Sent: Tuesday, February 17, 2009 11:12 PM
Subject: [BasicX] Re: Variable Conversion BX-24
Hello Patrick
How about redelcare the vars as Byte, simplify 0.031 with 0.03 and
make I1 = V1/0.03 = V1*33 (NOTE that V1/0.03 is not allowed!)
That would give a value of '9' which is from what you say just
enough .... ?
Regards
Olle
--- In b...@yahoogroups.com, "gouardopatrick"
wrote:
>
> Hello Everybody,
>
> In my program top read a current, I have declared the following:
>
> Dim I1 as Single
> Dim V1Max as Single
>
> And them I do something like that:
>
> I1=V1Max / 0.031
> Debug.Print "V1Max = "; CStr(V1Max);" "; "I1 = ";CStr(I1)
>
> The result on my PC is a value of for example I1 = 9,23456
>
> How can I modify to read only 9,2 , only one decimal which is more
> than enough.
>
> My intention later is to compare I1 in a conditional statement like
> If I1 >20 then Switch off Radiator 1 using X10 command
> If I1 >25 then Switch off Radiator 2 using X10 command
>
> I may also send the current of each phase and Neutral to an LCD
> display to read in real time the consumed current.
>
> Thanks and Best Regards.
>
> Patrick.
>
[Non-text portions of this message have been removed]
------------------------------------
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )Re: Variable Conversion BX-24 - Olle Bengtsson - Feb 18 14:04:48 2009
Hi Eric
I just meant that if the variables are Bytes as I suggested, one
cannot do any float division, the compiler will scream :-)
But I wonder if not Rosarite have the simplest solution - use CInt on
the result
All the best!
/Olle
--- In b...@yahoogroups.com, "eserdahl@"
wrote:
>
> Hello Olle,
>
> I don't understand your statement, "(NOTE that V1/0.031 is
> not allowed!)".
>
> Dividing a floating point variable (single) by a floating point
> constant (single) seems to work on my BX-24?
>
> Eric
>
> ----- Original Message -----
> From: Olle Bengtsson
> To: b...@yahoogroups.com
> Sent: Tuesday, February 17, 2009 11:12 PM
> Subject: [BasicX] Re: Variable Conversion BX-24
> Hello Patrick
> How about redelcare the vars as Byte, simplify 0.031 with 0.03 and
> make I1 = V1/0.03 = V1*33 (NOTE that V1/0.03 is not allowed!)
> That would give a value of '9' which is from what you say just
> enough .... ?
> Regards
> Olle
------------------------------------

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )