Skip to content

Instantly share code, notes, and snippets.

@GiovanniBalestrieri
Created March 14, 2017 21:58
Show Gist options
  • Save GiovanniBalestrieri/738440f51de951cd644caa3ef953ed85 to your computer and use it in GitHub Desktop.
Save GiovanniBalestrieri/738440f51de951cd644caa3ef953ed85 to your computer and use it in GitHub Desktop.
Accelerometer Basic ADXL345
//Analog read pins
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;
int xRead,yRead,zRead;
void setup()
{
Serial.begin(9600);
Serial.println("Ready!");
}
void loop()
{
readAcc();
printVals();
delay(500);
}
// Read analog values from the Acc
void readAcc()
{
xRead = analogRead(xPin);
yRead = analogRead(yPin);
zRead = analogRead(zPin);
}
void printVals()
{
Serial.print(" X: ");
Serial.print(xRead);
Serial.print(" | Y: ");
Serial.print(yRead);
Serial.print(" | Z: ");
Serial.print(zRead);
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment