-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSerial_Reader.ino
49 lines (41 loc) · 1.28 KB
/
Serial_Reader.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* This example demonstrates how multiple threads can subscribe to
* reading from the same physical Serial interface. Incoming data
* is copied into per-thread receive buffers so that no thread
* can "steal" data from another thread by reading it first.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <Arduino_Threads.h>
/**************************************************************************************
* SETUP/LOOP
**************************************************************************************/
void setup()
{
Serial.begin(9600);
while (!Serial) { }
Thread_1.start();
Thread_2.start();
Thread_3.start();
Serial.block();
Serial.println("Thread #0 started.");
Serial.unblock();
}
void loop()
{
/* Read data from the serial interface into a String. */
String serial_msg;
while (Serial.available())
serial_msg += (char)Serial.read();
/* Print thread id and chip id value to serial. */
if (serial_msg.length())
{
Serial.block();
Serial.print("[");
Serial.print(millis());
Serial.print("] Thread #0: ");
Serial.print(serial_msg);
Serial.println();
Serial.unblock();
}
}