Tilt Sample
This application demonstrates reading tilt states of X, Y, and Z axes.
To run the example:
  1. 1.
    Open the IoT_Node_AccelTilt_Tilt sketch from the examples menu.
  2. 2.
    Select Turta IoT Node from the Tools > Board menu.
  3. 3.
    Select your device's COM port from Tools > Port menu.
  4. 4.
    Open Serial Monitor from Tools > Serial Monitor.
  5. 5.
    Select 115.200 baud from the Serial Monitor's status bar.
  6. 6.
    Upload the code to your device.

Sample Code

IoT_Node_AccelTilt_Tilt.ino
#include <Turta_AccelTilt_Module.h>
// Create Accel & Tilt Sensor instance.
Turta_AccelTilt_Module accel;
void setup() {
// Initialize Accel & Tilt Sensor.
accel.begin();
// Configure serial port.
Serial.begin(115200);
delay(200);
}
void loop() {
// Read Tilt State.
bool xTilt, yTilt, zTilt;
accel.readTiltState(xTilt, yTilt, zTilt);
Serial.print("X: ");
Serial.print(xTilt ? "Tilt" : "Flat");
Serial.print(", Y: ");
Serial.print(yTilt ? "Tilt" : "Flat");
Serial.print(", Z: ");
Serial.println(zTilt ? "Tilt" : "Flat");
// Delay 100ms.
delay(100);
}

Result

After the application is uploaded to the device, it writes tilt states to the Serial Monitor. The example output should be like this:
X: Flat, Y: Flat, Z: Tilt
X: Flat, Y: Flat, Z: Tilt
X: Flat, Y: Tilt, Z: Flat
X: Flat, Y: Tilt, Z: Flat
The application runs forever until you clear it from memory.
Copy link
On this page
Sample Code
Result