mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
compiling
This commit is contained in:
63
lib/ArduinoStreamUtils/examples/EepromRead/EepromRead.ino
Normal file
63
lib/ArduinoStreamUtils/examples/EepromRead/EepromRead.ino
Normal file
@@ -0,0 +1,63 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to read from EEPROM
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
#if STREAMUTILS_ENABLE_EEPROM
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
Serial.println("Initializing EEPROM...");
|
||||
EEPROM.begin(512);
|
||||
#endif
|
||||
|
||||
Serial.println("Make sure to run the EepromWrite example first!");
|
||||
|
||||
Serial.println("Reading EEPROM... ");
|
||||
EepromStream s(0, 12);
|
||||
Serial.print(s.readString());
|
||||
|
||||
#else
|
||||
Serial.println("EepromStream is not supported on this platform. Sorry");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// not used in this example
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
69
lib/ArduinoStreamUtils/examples/EepromWrite/EepromWrite.ino
Normal file
69
lib/ArduinoStreamUtils/examples/EepromWrite/EepromWrite.ino
Normal file
@@ -0,0 +1,69 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to read from EEPROM
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
#if STREAMUTILS_ENABLE_EEPROM
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
Serial.println("Initializing EEPROM...");
|
||||
EEPROM.begin(512);
|
||||
#endif
|
||||
|
||||
Serial.println("Writing to EEPROM...");
|
||||
EepromStream s(0, 12);
|
||||
s.print("Hello World!");
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
Serial.println("Saving...");
|
||||
s.flush(); // only required on ESP
|
||||
#endif
|
||||
|
||||
Serial.println("Done!");
|
||||
Serial.println("Now, run the EepromRead example.");
|
||||
|
||||
#else
|
||||
Serial.println("EepromStream is not supported on this platform. Sorry");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// not used in this example
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
@@ -0,0 +1,68 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to use Hamming codes for error correction
|
||||
//
|
||||
// To run this program, you need two boards that support Serial1 with the same
|
||||
// voltage. For example: Arduino Mega, Leonardo, or Nano Every (all 5V boards)
|
||||
//
|
||||
// Connect the TX pin of one board to the RX pin of the other and vice-versa.
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
HammingStream<7, 4> eccSerial1(Serial1);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
Serial1.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
// Discard any remaining data in the input buffer
|
||||
while (Serial1.available())
|
||||
Serial1.read();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Did we receive something?
|
||||
if (eccSerial1.available())
|
||||
// Print it
|
||||
Serial.write(eccSerial1.read());
|
||||
|
||||
// Do we have something to send?
|
||||
if (Serial.available())
|
||||
// Sent it
|
||||
eccSerial1.write(Serial.read());
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
@@ -0,0 +1,67 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to use Hamming codes for error correction
|
||||
//
|
||||
// To run this program, you need two boards connected like so:
|
||||
// BOARD 1 - BOARD 2
|
||||
// pin 10 - pin 11
|
||||
// pin 11 - pin 10
|
||||
//
|
||||
// SoftwareSerial is here for demonstration purposes; please don't use it in
|
||||
// production, as it is notoriously unreliable.
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <StreamUtils.h>
|
||||
|
||||
SoftwareSerial linkSerial(10, 11); // RX, TX
|
||||
HammingStream<7, 4> eccLinkSerial(linkSerial);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
linkSerial.begin(4800);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Did we receive something?
|
||||
if (eccLinkSerial.available())
|
||||
// Print it
|
||||
Serial.write(eccLinkSerial.read());
|
||||
|
||||
// Do we have something to send?
|
||||
if (Serial.available())
|
||||
// Sent it
|
||||
eccLinkSerial.write(Serial.read());
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
61
lib/ArduinoStreamUtils/examples/Logger/Logger.ino
Normal file
61
lib/ArduinoStreamUtils/examples/Logger/Logger.ino
Normal file
@@ -0,0 +1,61 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to log what goes through a Stream, both reads and
|
||||
// writes operations.
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
// Create a new stream that will forward all calls to Serial, and log to Serial.
|
||||
// Everything will be written twice to the Serial!
|
||||
LoggingStream loggingStream(Serial, Serial);
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
// Write to the serial port.
|
||||
// Because loggingStream logs each write operation, the string will we written
|
||||
// twice
|
||||
loggingStream.println("Hello World!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Read from the serial port.
|
||||
// Because loggingStream logs each read operation, everything we read is
|
||||
// printed back to the serial port.
|
||||
while (loggingStream.available()) {
|
||||
loggingStream.read();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
56
lib/ArduinoStreamUtils/examples/ReadBuffer/ReadBuffer.ino
Normal file
56
lib/ArduinoStreamUtils/examples/ReadBuffer/ReadBuffer.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to buffer the read operations of a stream.
|
||||
//
|
||||
// Like "echo," it reads from the serial port and prints back the same thing.
|
||||
// What's interesting with this program is that it reads the input in chunks of
|
||||
// 64 bytes, even if it seems to read them one by one.
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
ReadBufferingStream bufferedSerial{Serial, 64};
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Even if it looks like the bytes are extracted one by one, they are actually
|
||||
// read by chunks of 64 bytes and placed in a buffer.
|
||||
while (bufferedSerial.available()) {
|
||||
Serial.write(bufferedSerial.read());
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
55
lib/ArduinoStreamUtils/examples/ReadLogger/ReadLogger.ino
Normal file
55
lib/ArduinoStreamUtils/examples/ReadLogger/ReadLogger.ino
Normal file
@@ -0,0 +1,55 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to log what read from a Stream
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
// Create a new stream that will forward all calls to Serial, and log to Serial.
|
||||
// It will write back everything it reads, just like "echo"
|
||||
ReadLoggingStream loggingStream(Serial, Serial);
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Read the serial port.
|
||||
// Because loggingStream write everything it read, the program will show what
|
||||
// you sent.
|
||||
while (Serial.available()) {
|
||||
loggingStream.write(Serial.read());
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
54
lib/ArduinoStreamUtils/examples/StringPrint/StringPrint.ino
Normal file
54
lib/ArduinoStreamUtils/examples/StringPrint/StringPrint.ino
Normal file
@@ -0,0 +1,54 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to use StringPrint
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
StringPrint stream;
|
||||
|
||||
stream.print("Temperature = ");
|
||||
stream.print(22.3);
|
||||
stream.print(" °C");
|
||||
|
||||
Serial.print(stream.str());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// no used in this example
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
@@ -0,0 +1,55 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to use StringStream
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
StringStream stream;
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
stream.print("Temperature = ");
|
||||
stream.print(22.3);
|
||||
stream.print(" °C");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (stream.available() > 0) {
|
||||
Serial.print((char)stream.read());
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
62
lib/ArduinoStreamUtils/examples/WriteBuffer/WriteBuffer.ino
Normal file
62
lib/ArduinoStreamUtils/examples/WriteBuffer/WriteBuffer.ino
Normal file
@@ -0,0 +1,62 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to buffer writes to a stream.
|
||||
//
|
||||
// Like "echo," it reads from the serial port and prints back the same thing.
|
||||
// What's interesting with this program is that it writes in chunks of
|
||||
// 8 bytes, even if it seems to write them one by one.
|
||||
//
|
||||
// As you'll see, you need to type at least 8 bytes to see something. That's
|
||||
// because it waits for the buffered to be full before sending it to the serial.
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
// Create a new Stream that buffers all writes to Serial
|
||||
WriteBufferingStream bufferedSerial{Serial, 8};
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
Serial.println(F("Send at least 8 bytes to see the result"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Even if it looks like the bytes are sent one by one, they are actual
|
||||
// written in chunks of 8 bytes.
|
||||
while (Serial.available()) {
|
||||
bufferedSerial.write(Serial.read());
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
55
lib/ArduinoStreamUtils/examples/WriteLogger/WriteLogger.ino
Normal file
55
lib/ArduinoStreamUtils/examples/WriteLogger/WriteLogger.ino
Normal file
@@ -0,0 +1,55 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to log what written to a Stream
|
||||
|
||||
#include <StreamUtils.h>
|
||||
|
||||
// Create a new stream that will forward all calls to Serial, and log to Serial.
|
||||
// Everything will be written twice to the Serial!
|
||||
WriteLoggingStream loggingStream(Serial, Serial);
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
|
||||
// Write to the serial port.
|
||||
// Because loggingStream logs each write operation, the string will we written
|
||||
// twice
|
||||
loggingStream.println("Hello World!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// not used in this example
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* Love this project? *
|
||||
* Star it on GitHub! *
|
||||
* *
|
||||
* .,,. *
|
||||
* ,,:1. *
|
||||
* ,.,:;1 *
|
||||
* .,,,::;: *
|
||||
* ,,,,::;;. *
|
||||
* .,,,:::;;; *
|
||||
* .....,,,,...,.,,,,,,:::,,,,,,,,,,,,, *
|
||||
* ,,,,,,,,,,,:,...,,,,,,:::,,,,:::;;;11l *
|
||||
* .;::::::::,,,,,,,,,,:::::,,::;;;1lt *
|
||||
* .;;;:::,,,,,,,,::::::;:::;;1t: *
|
||||
* :;;:,,,,,,::::::;;;;;;l1 *
|
||||
* ,,,,:::::::;;;;;;l *
|
||||
* .,,,,::::;;;;;;;:::: *
|
||||
* ,,,,,:::;;;;;::,:::1 *
|
||||
* ,,,,,::;;;t1:,,:::::;l *
|
||||
* .,,,,:;;ll ;::::::;;, *
|
||||
* ,,,:;ll. .1:::;;l *
|
||||
* .,:lt, .1;;l: *
|
||||
* *
|
||||
* https://github.com/bblanchon/ArduinoStreamUtils *
|
||||
* *
|
||||
*****************************************************/
|
||||
Reference in New Issue
Block a user