Adding header and cpp files to Arduino folder

arduino m0 files header cpp src folder

This example shows how to add more files (such as *.h and *.cpp) to a current Arduino project without making it into an Arduino library.

Example folder structure:

.
├── Makefile
├── main.ino
└── src
    └── foo
        ├── foo.cpp
        └── foo.h

Code

Download code
#include "src/foo/foo.h"

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

    SerialUSB.println("Start!");
}
void loop() {
    bar();
    delay(2000);
}

Makefile

BOARD?=arduino:samd:arduino_zero_native
PORT := $(shell ls /dev/cu.usbmodem*)

.PHONY: default lint all flash clean

default: lint all flash clean

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

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

flash:
	arduino-cli upload -p $(PORT) --fqbn $(BOARD)

clean:
	rm -r build

Serial console

Serial output from the firmware.

Adding header and cpp files to Arduino folder serial console

References