Arithmetic Operator question
code: [select]
int z;
float gz = analogread(z)*0.0048828125 - 1.66;
hope can me understand wrong above piece of code.
as know analog reading number between 0-1023.
so let assume analogread(z) @ given time 250, in multiplication 0.0048828125 return 1.220703125.
then 1.220703125 - 1.66 should return -0.439296875.
but return positive number of 0.439296875.
the intresting part me if go below -1.000 value return same code return correct negativ value of
-1.000. :-?
this part of bigger code calculates analog g-sensor value in volts , g force. therfore 5/1024 = 0.0048828125 volt calculation.
hulk,
assuming z uninitialized automatic (stack) variable , reading pin z, (potentially) reading undefined pin. therefore return analogread unpredictable.
the expression assigned gz works fine long analogread() indeed returning number between 0 , 1023.
mikal
assuming z uninitialized automatic (stack) variable , reading pin z, (potentially) reading undefined pin. therefore return analogread unpredictable.
the expression assigned gz works fine long analogread() indeed returning number between 0 , 1023.
mikal
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Arithmetic Operator question
arduino
Comments
Post a Comment