Display command on serial and telnt (optimisation)


hi in program have debug want display debug.
the user can connected serial or telnet.

for moment have same write 2 time example "debug xxxxx" (it's bigger in program)
code: [select]

serial.print(f("debug xxxxx"));
.
.
telnet.print(f("debug xxxxx"));


my first idea create function
code: [select]

string displaydebug() {
answer+="debug xxxxx";
answer+="xxxxx"
return answer;
}
serial.print(displaydebug()));
.
.
telnet.print(displaydebug());


but thing string answer can long take many memory

do have idea ?


not sure follow want.
this use debug printing.
you can add macros needed.

edit: corrected typo in sketch

code: [select]

/*
  blink
 turns on led on 1 second, off 1 second, repeatedly.
 
 this example code in public domain.
 */

//***************************************************************
#define debug       //if comment line dprint & dprintln
//lines defined blank.
//examples:
//dprintln("testing123");   
//dprintln(0xc0ffeeul,dec);
//dprintln(12648430ul,hex);

#ifdef debug
#define dprint(...)    serial.print(__va_args__)
#define dprintln(...)  serial.println(__va_args__)
#define drintf(...)    serial.print(f(__va_args__))
#define dprintlnf(...) serial.println(f(__va_args__))

#else
#define dprint(...)    //blank line
#define dprintln(...)  //blank line
#define dprintf(...)    //blank line
#define dprintlnf(...)  //blank line

#endif
//***************************************************************

// pin 13 has led connected on arduino boards.
// give name:
int led = 13;

int z = 123;

void setup() {               
  // initialize digital pin output.
  pinmode(led, output);     
  serial.begin(9600);

}

void loop() {
  digitalwrite(led, high);  // turn led on (high voltage level)
  delay(1000);              // wait second
  digitalwrite(led, low);   // turn led off making voltage low
  delay(1000);              // wait second

  dprintln("testing123");
  dprintln(0xc0ffeeul,dec);
  dprintln(12648430ul,hex);
  dprintlnf("this in flash");
  dprintln( z );
  dprintln();
}



Arduino Forum > Using Arduino > Programming Questions > Display command on serial and telnt (optimisation)


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code