SerialDebug_basic.ino
3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
////////
// Libraries Arduino
//
// Library: SerialDebug - Improved serial debugging to Arduino, with simple software debugger
// Author: Joao Lopes
// GitHub: https://github.com/JoaoLopesF/SerialDebug
//
// Basic example to show how to use it.
//
// Example of use:
//
// print macros:
//
// printA(F("This is a always - var "));
// printlnA(var);
// printV(F("This is a verbose - var "));
// printlnV(var);
// printD(F("This is a debug - var "));
// printlnD(var);
// printI(F("This is a information - var "));
// printlnI(var);
// printW(F("This is a warning - var "));
// printlnW(var);
// printE(F("This is a error - var "));
// printlnE(var);
//
// printlnV("This not have args");
//
///////
////// Includes
#include "Arduino.h"
// SerialDebug Library
// Disable all debug ? Good to release builds (production)
// as nothing of SerialDebug is compiled, zero overhead :-)
// For it just uncomment the DEBUG_DISABLED
//#define DEBUG_DISABLED true
// Define the initial debug level here (uncomment to do it)
// #define DEBUG_INITIAL_LEVEL DEBUG_LEVEL_VERBOSE
// Disable SerialDebug debugger ? No more commands and features as functions and globals
// Uncomment this to disable it
//#define DEBUG_DISABLE_DEBUGGER true
// Disable auto function name (good if your debug yet contains it)
//#define DEBUG_AUTO_FUNC_DISABLED true
// Force debug messages to can use flash ) ?
// Disable native Serial.printf (if have)
// Good for low memory, due use flash, but more slow and not use macros
//#define DEBUG_USE_FLASH_F true
// Include SerialDebug
#include "SerialDebug.h" //https://github.com/JoaoLopesF/SerialDebug
////// Variables
// Time
uint32_t mTimeSeconds = 0;
// Buildin Led ON ?
boolean mLedON = false;
////// Setup
void setup() {
// Initialize the Serial
Serial.begin(115200); // Can change it to 230400, if you dont use debugIsr* macros
#ifdef __AVR_ATmega32U4__ // Arduino AVR Leonardo
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
#else
delay(500); // Wait a time
#endif
// Debug
// Attention:
// SerialDebug starts disabled and it only is enabled if have data avaliable in Serial
// Good to reduce overheads.
// if You want debug, just press any key and enter in monitor serial
// Note: all debug in setup must be debugA (always), due it is disabled now.
printlnA(F("**** Setup: initializing ..."));
// Buildin led
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// WiFi connection, etc ....
// ...
// End
printlnA(F("*** Setup end"));
}
////// Loop
void loop()
{
// SerialDebug handle
// Notes: if in inactive mode (until receive anything from serial),
// it show only messages of always or errors level type
// And the overhead during inactive mode is very low
// Only if not DEBUG_DISABLED
debugHandle();
// Blink the led
mLedON = !mLedON;
digitalWrite(LED_BUILTIN, (mLedON)?LOW:HIGH);
// Debug the time (verbose level)
printV(F("Time: "));
printV(mTimeSeconds);
printlnV(F(" seconds (VERBOSE)"));
if (mTimeSeconds % 5 == 0) { // Each 5 seconds
// Debug levels
printlnV(F("This is a message of debug level VERBOSE"));
printlnD(F("This is a message of debug level DEBUG"));
printlnI(F("This is a message of debug level INFO"));
printlnW(F("This is a message of debug level WARNING"));
printlnE(F("This is a message of debug level ERROR"));
// Functions example to show auto function name feature
foo();
bar();
}
// Time
mTimeSeconds++;
// Delay of 1 second
delay(1000);
}
// Functions example to show auto function name feature
void foo() {
uint8_t var = 1;
printV(F("This is a debug - var "));
printlnV(var);
}
void bar() {
uint8_t var = 2;
printD(F("This is a debug - var "));
printlnD(var);
}
/////////// End