// serial connection - serial monitor
void setup() {
Serial.begin(9600); // setting up baud rate
// initialize serial connection
Serial.println("Booting up ..... ");
digitalWrite(LED_BUILTIN, LOW);
}
String command;
int incomingByte = 0;
int _led = 0;
const int BUFFER_SIZE = 50;
char buffer[BUFFER_SIZE];
void loop() {
Serial.println("esp32io.com"); // mit Zeilenvorschub
Serial.print("text in");
Serial.println("gleicher zeile"); // ohne Zeilenvorschub
Serial.print("Was ist im buffer: ");
Serial.println(Serial.available()); // is there something in the serial buffer, nothing=0, something!=0
Serial.println();
Serial.write(43); // ASCII-Zeichen "+"
Serial.write(45); // write a byte with the value 45 => '-' character
Serial.write('\n'); // write a newline character
Serial.write("esp32 - GetStarted \n"); // write a string terminated by a newline character
byte buf[] = {'A', 'r', 'd', 'u', 'i', 'n', 'o'};
Serial.write(buf, 7); // write an array
/*
if (Serial.available()) { // if there is data comming function != 0
Serial.print("Eingabe eines Textes: "); // S T R I N G - R E A D
command = Serial.readStringUntil('\n'); // after ENTER the buffer will receive string
Serial.println("eingegeben wurde: "); // after ENTER Serial.available() != 0
Serial.println(command);
}
*/
/*
if (Serial.available() > 0) { // check if data is available
int rlen = Serial.readBytes(buffer, BUFFER_SIZE); // read the incoming bytes:
Serial.print("I received: "); // prints the received string/text
for(int i = 0; i < rlen; i++) // single C H A R - R E A D
Serial.print(buffer[i]);
}
*/
/*
if (Serial.available() > 0) { // check if data is available, Serial.available() = sum of input + \n
incomingByte = Serial.read(); // read the incoming byte:
Serial.print("I received: "); // prints the received data, --byte-by-byte--
Serial.println((char)incomingByte); // single C H A R - R E A D
}
*/
_led = Serial.read(); // read string until newline character;
if (_led == '1') {
digitalWrite(LED_BUILTIN, HIGH); // turn on LED
Serial.println("Turn LED ON");
} else if (_led == '0') { // single C H A R - R E A D
digitalWrite(LED_BUILTIN, LOW); // turn off LED
Serial.println("Turn LED OFF");
}
/*
Serial.read();
Serial.readBytes();
Serial.find();
Serial.end(); // disables serial communication, RX & TX can be used otherwise. Restart with Serial.begin()
*/
delay(2000);
}