IDE Suggestion :- Processing style 'println'

I have been using Arduino IDE much longer then I have been using Processing, but one nice feature in Processing is the ability to string along several 'pieces' of things you want to print without the need to resort to sprintf, for example this is valid in Processing, but not in Arduino.

println("Found Arduino with 0x" + hex(capacity) + " byte flash chip.");

It would avoid the need for endless Serial.print(); or sprintf usage.

Regards,

Graham

Maybe you ought to look at HOW Processing accomplishes that.

I can't find any .h or .cpp files or I would have looked. And I don't understand the .jar crap.

Regards,

Graham

Basically, its using a String lib. “text” is treated as a String. Everything is concatenated before even being passed to println.

If you use the ‘latest hourly build’ which has C++ enabled, you can use the streaming functionality in my PrintEx lib (download from within the IDE lib manager). Info here.

#include <PrintEx.h>

using namespace ios;

const long capacity = FLASHEND;

void setup() {
  Serial.begin(9600);

  Serial << "Found Arduino with 0x" << hex << capacity << " byte flash chip.";
}

void loop() {}

Thank you Pyro, that is helpful.

Regards,

Graham

No worries,

I have just updated my lib and you can now use the same streaming functionality within a function. Its basically the same thing as I posted above, just a different interface. This will be available within an hour in the lib manager (version 1.1.9).

#include <PrintEx.h>

using namespace ios;

const unsigned long capacity = FLASHEND;

PrintEx serial = Serial;

void setup() {
  Serial.begin(9600);

  serial.printx("Found Arduino with 0x", hex, capacity, " byte flash chip.");
}

void loop() {}

That is even better! :slight_smile: Apart from a minor syntax difference that was exactly what I was after.

Would I be right in thinking it could also be used for LCD character display for example PrintEx serial = lcd;?

How big does the library compile to? Personally I am using a DUE, but a guy on the forums was asking about the same thing as me, and I believe he only has an UNO.

Regards,

Graham

It supports AVR, SAM (Due), SAMD (Zero), & ESP8266, possibly more (or with minor tweaks), however this is all I've had a chance to test.

If the lcd object you are using supports Stream or Print, then yes it'll work. If you want to read through the same PrintEx object, you can actually use StreamEx (if your lib uses Stream, not just Print).

The size of the code is purely dependent on what you use. For example, using the streaming/printx feature to replace extensive print/println usage can actually produce smaller code.

Using the printf function (what you wanted to avoid) will incur an overhead as its quite an involved function, but is smaller than using a mix of the Arduino sprintf and print() (mine uses print() so it will not be much if you are already using the functionality, and it supports floats & other features missing in the default).

Check the readme for functionality and usage (its still needs a lot more info, but there is alot documented already).

Its important however that you either manually enable C++11 in earlier versions, or use the latest hourly build for 1.6.6 (best option) which has it enabled by default. The oldest version that you can enable C++11 in is 1.5.7 however there is no lib manager.