I used serial port to receive information from Arduino, even when the program doesn’t need the use of communication. Doing so becomes easy generate some Debugging Messages from the MCU.

But this requires you to program several lines that finally must be deleted or commented, using // .

That’s the reason I decided to provide my programs with a new functional library that should give the possibility to use Serial Port as debugging communication channel and that must be enabled or disabled easily.  I’ve programmed a class called Debug and can be used as shown in the exemple.

#include <Debug.h>

Debug DebugPort=Debug();

int value;

void setup(){
 DebugPort.setBaudrate(9600);
 pinMode(2, INPUT);
 pinMode(13,OUTPUT);

if (digitalRead(2)==0){                          //if pin2 is down at startup, enables the debugging
 DebugPort.enable();
 }else{
 DebugPort.disable();
 }
 if (DebugPort.GetStatus()) digitalWrite(13,HIGH);  //Shows debugging state in LED
 }

void loop(){
 value=analogRead(0);                                           //dummy program
 analogWrite(6,value/4);

DebugPort.print("Debugging Message: ");          //Debugging lines are shown if DEBUG is enabled, skip if not
 DebugPort.println(value);
 delay(1000);
 }

Library is ready to download in Libraries section.

Anuncios