You just need to define a variable that they both use; something like:
/*
Reading and controlling the very low power LIS2DH12
Author: Nathan Seidle
Created: Septempter 18th, 2019
License: This code is Lemonadeware; do whatever you want with this code.
If you see me (or any other SparkFun employee) at the
local, and you’ve found our code helpful, please buy us a round!
This example demonstrates how to read XYZ from the LIS2DH12.
Feel like supporting open source hardware?
Buy a board from SparkFun!
Edge: https://www.sparkfun.com/products/15170
Edge 2: https://www.sparkfun.com/products/15420
Qwiic LIS2DH12 Breakout: https://www.sparkfun.com/products/15760
Hardware Connections:
Plug a Qwiic cable into the Qwiic Accelerometer RedBoard Qwiic or BlackBoard
If you don’t have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/
#include <Wire.h>
#include <SerLCD.h>
#include “SparkFun_LIS2DH12.h” //Click here to get the library: http://librarymanager/All#SparkFun_LIS2DH12
SPARKFUN_LIS2DH12 accel; //Create instance
SerLCD lcd;
void setup()
{
Serial.begin(115200);
Serial.println(“SparkFun Accel Example”);
Wire.begin();
lcd.begin(Wire); //Set up the LCD for I2C communication
lcd.setBacklight(255, 255, 255); //Set backlight to bright white
lcd.setContrast(5); //Set contrast. Lower to 0 for higher contrast.
lcd.clear(); //Clear the display - this moves the cursor to home position as well
//lcd.print(“Hello, World!”);
if (accel.begin() == false)
{
Serial.println(“Accelerometer not detected. Check address jumper and wiring. Freezing…”);
while (1)
;
}
}
void loop()
{
//Print accel values only if new data is available
if (accel.available())
{
float accelX = accel.getX();
float accelY = accel.getY();
float accelZ = accel.getZ();
float tempC = accel.getTemperature();
Serial.print("Acc [mg]: ");
Serial.print(accelX, 1);
Serial.print(" x, ");
Serial.print(accelY, 1);
Serial.print(" y, ");
Serial.print(accelZ, 1);
Serial.print(" z, ");
Serial.print(tempC, 1);
Serial.print(“C”);
Serial.println();
delay(100);
lcd.clear();
lcd.print(accelX, 1);
lcd.print("X Y ");
lcd.print(accelY, 1);
delay(200);
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(accelZ, 1);
delay(200);
//delay(100);
// Set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// int rawX = accel.getRawX();
// int rawY = accel.getRawY();
// int rawZ = accel.getRawZ();
//
// Serial.print("Acc raw: ");
// Serial.print(rawX);
// Serial.print(" x, ");
// Serial.print(rawY);
// Serial.print(" y, ");
// Serial.print(rawZ);
// Serial.print(" z");
// Serial.println();
}
}
Should get you very close…something is wrong with Z (5 digits instead of 3?) but this get ya 90% there