Split up code into more ino files

arduino nano 33 ble sense imu sensors LSM9DS1 HTS221

Pre-requisites

Display IMU, temperature and humidity data with Arduino board Nano 33 BLE Sense with IMU LSM9DS1 and sensor HTS221.

Install the dependancy:

arduino-cli lib install Arduino_LSM9DS1
arduino-cli lib install Arduino_HTS221

Split up the code into various *.ino files with a folder structure like this:

$ tree
.
├── Makefile
├── imu.ino
├── nano33-ble-sense-more-ino.ino
└── sensor.ino

Code

Download code
#include <Arduino_HTS221.h>
#include <Arduino_LSM9DS1.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) {}

  if (!initSensor()) {
    Serial.println("Failed to initialize humidity temperature sensor!");
  }

  if (!initIMU()) {
    Serial.println("Failed to initialize IMU!");
  }

  Serial.println("Let's start!");
}

void loop() {
  float temperature;
  float humidity;
  getSensorValues(&temperature, &humidity);

  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity = ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.println();

  delay(1000);

  float x, y, z;
  if (getAcceleration(&x, &y, &z)) {
    Serial.print("X: ");
    Serial.print(x);
    Serial.print('\t');

    Serial.print("Y: ");
    Serial.print(y);
    Serial.print('\t');

    Serial.print("Z: ");
    Serial.println(z);
  }
}

Makefile

BOARD?=arduino:mbed:nano33ble
PORT?=/dev/cu.usbmodem14*
BUILD=build

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright,-runtime/int *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

References