Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created July 22, 2024 03:11
Show Gist options
  • Save hidsh/44bcc5cde4c6ab9893b343a8e26d72ea to your computer and use it in GitHub Desktop.
Save hidsh/44bcc5cde4c6ab9893b343a8e26d72ea to your computer and use it in GitHub Desktop.
arduino example: calling Serial.println() from a C++ source file
#include "sub.h"
void setup(){
Serial.begin(9600);
delay(0.5 * 1000);
my_log("foo");
}
void loop(){
my_log("bar");
delay(1 * 1000);
}
// sub.cpp
#include <Arduino.h>
#include "sub.h"
void my_log(const char *msg) {
Serial.println(msg);
}
// sub.h
#ifdef __cplusplus
extern "C" {
#endif
void my_log(const char *msg);
#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment