#include <looptime.h>
#include <linscale.h>

/*
simple program which read acc x,y,z
convert to float by scaling parms 
(use -1g and 1g meas by cansat/calibacc
*/

struct linscaletp accx,accy,accz;

void setup()
{
  Serial.begin(9600);
  linscaleinit(&accx,183,-1.0,515,1.0); // -1g and 1g meas
  linscaleinit(&accy,181,-1.0,524,1.0);
  linscaleinit(&accz,150,-1.0,483,1.0);
}

float ax,ay,az,r;
void loop()
{
  ax = linscale(analogRead(2),&accx);
  ay = linscale(analogRead(3),&accy);
  az = linscale(analogRead(1),&accz);
  Serial.print(ax); Serial.print(" ");
  Serial.print(ay); Serial.print(" ");
  Serial.print(az); Serial.print(" xx ");
  r = sqrt(ax*ax+ay*ay+az*az);
  Serial.println(r);
  looptime(50);
}




