Difference between revisions of "A Tarduino example done properly"
Jump to navigation
Jump to search
Tag: Manual revert |
|||
(11 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
= main.cpp = | = main.cpp = | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="cpp" line="1"> | ||
#include <Arduino.h> // Pretty much only here to giv us Serial Communications & delay() | #include <Arduino.h> // Pretty much only here to giv us Serial Communications & delay() | ||
Line 18: | Line 18: | ||
Serial.begin(115200); | Serial.begin(115200); | ||
Serial.println("Howdee!"); | Serial.println("Howdee!"); | ||
Serial.println(); | |||
delay(5000); // What a silly way to rape a microcontroller... | delay(5000); // What a silly way to rape a microcontroller... | ||
} | } | ||
Line 29: | Line 30: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
(Let's not discuss the horror that is <code class="mwt-code" >delay()</code> for now. Maybe in another article...) | |||
= FooBar.h = | = FooBar.h = | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="cpp" line="1"> | ||
void Function1(); | void Function1(); | ||
Line 59: | Line 62: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=platformio.ini= | =platformio.ini= | ||
Line 65: | Line 67: | ||
(Coz I have this preference in IDEs...) | (Coz I have this preference in IDEs...) | ||
<syntaxhighlight lang="ini" line="1"> | |||
[env:uno] | |||
platform = atmelavr | |||
board = uno | |||
framework = arduino | |||
monitor_speed = 115200 | |||
</syntaxhighlight> | |||
[[Category:Coding]] | |||
[[Category:Arduino]] | |||
[[Category:C Cpp]] | |||
[[Category:PlatformIO]] |
Latest revision as of 16:49, 3 January 2022
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!");
Serial.println();
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...
}
(Let's not discuss the horror that is delay()
for now. Maybe in another article...)
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:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200