Back to Parent

Setting Accelerometer Range
// Setting Accelerometer range

int xPin = A1;
int yPin = A2;
int zPin = A3;

int xReading, yReading, zReading; 

// Initial settings
int maxX = 0;
int minX = 5000;
int maxY = 0;
int minY = 5000;
int maxZ = 0;
int minZ = 5000;

void setup()
{
  Serial.begin(9600);

  xReading = analogRead(xPin);
  yReading = analogRead(yPin);
  zReading = analogRead(zPin);
}

void loop()
{
  xReading = analogRead(xPin);
  if(xReading > maxX) maxX = xReading;
  if(xReading < minX) minX = xReading;

  yReading = analogRead(yPin);
  if(yReading > maxY) maxY = yReading;
  if(yReading < minY) minY = yReading;

  zReading = analogRead(zPin);
  if(zReading > maxZ) maxZ = zReading;
  if(zReading < minZ) minZ = zReading;

  String outputOld = "";
  String output = outputOld.format("xR: %d, yR: %d, zR: %d", xReading, yReading, zReading);
  String outputOld2 = "";
  String output2 = outputOld2.format("xMax: %d, xMin: %d, yMax: %d, yMin: %d, zMax: %d, zMin: %d", maxX, minX, maxY, minY, maxZ, minZ);
  
  delay(100);
}
(2017) Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0