A Tarduino example done properly

From Da Nerd Mage Wiki
Revision as of 13:52, 27 December 2021 by Tinker (talk | contribs)
Jump to navigation Jump to search

The Arduino programming language is a superset of C++.

C++ is a superset of C.

For some strange reason, the people who developed Arduino decided to eliminate a lot of the constraints of C & C++ that make the code maintainable.

Luckily, you can program in C or C++ using proper techniques & compilers for Arduino will not choke on your code.

main.cpp

#include <Arduino.h>  // Pretty much only here to giv us Serial Communications & delay()

#include "FooBar.h"   // This header file lives in the src directory

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Howdee!");
  delay(5000);   // What a silly way to rape a microcontroller...
}

void loop() {
  // put your main code here, to run repeatedly:
  Function1();
  delay(1000);   // UGH...
  Function2();
  delay(1000);   // UGH...
}

FooBar.h

void Function1();

void Function2();

Function1.cpp

#include <Arduino.h>

void Function1()
{
    Serial.println("Hi Grant!");
}

Function2.cpp

#include <Arduino.h>

void Function2()
{
    Serial.println("I'm a microcontroller...");
}


platformio.ini

(Coz I have this preference in IDEs...)

[env:esp07]
platform = espressif8266
board = esp07
framework = arduino