Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: new to me: cout streaming for Teensy 2, 3

  1. #1
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828

    new to me: cout streaming for Teensy 2, 3

    This code with cout that works for Teensy 2, 3.x.
    I just encountered this library though it may have been around a while.
    Demo example of use of library:

    Code:
    #include <Streaming.h>
    
    void setup()
    {
      Serial.begin(9600);
      delay(5000); // <<<<<<<<<<<<<<<<<<<<<<<< I added this to give time to open serial terminal/monitor
      int lettera = 'A';
      int month = 4, day = 17, year = 2009;
      
      Serial << "This is an example of the new streaming" << endl;
      Serial << "library.  This allows you to print variables" << endl;
      Serial << "and strings without having to type line after" << endl;
      Serial << "line of Serial.print() calls.  Examples: " << endl;
      
      Serial << "A is " << lettera << "." << endl;
      Serial << "The current date is " << day << "-" << month << "-" << year << "." << endl;
      
      Serial << "You can use modifiers too, for example:" << endl;
      Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;
    }
    
    void loop()
    {}
    The library for Teensy/Arduino is explained at
    http://arduiniana.org/libraries/streaming/

    The latest version of Streaming is available http://arduiniana.org/Streaming/Streaming5.zip

    Download, drop the folder in the main IDE's library folder and try the example.
    Note that you can use, instead of "Serial", "Serial1" etc within the classes derived from Print.

  2. #2
    A little trick I learned as a replacement for the delay(5000) at the start of your code: while(!Serial){}

    Though, it's a poor choice if you would like it to run independently of having to open the serial monitor!

    Also, I think a similar function to this exists in the SDFat library, for those of you who already run it:

    Code:
    #include <SdFat.h>
    #include <SdFatUtil.h>
    
    ArduinoOutStream cout(Serial);
    
    void setup(){
      while(!Serial){}
      cout << "Hello, World!" << endl;
    }
    void loop(){}

  3. #3
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    regarding
    while(!Serial){}

    I and others have had intermittent trouble with the loop never-ending. So I have this delay habit.

  4. #4
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    894
    Plan for the weekend:

    - Cancel Birthday Party
    - try this with boost.format.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •