Hello i have the following code witch is working well
<if (mySerial.find(0x01))>
So i test if in the buffer there is the number 01 Hexadecimal, but i would like to test 3 numbers hexadecimal as
<if (mySerial.find(0x01, 0x04 , 0x04))>....
How can this be done and is it possible ?
And what is the difference between Stream ?
Thanks
The Stream class is a common class that used by a few other classes to give them a few extra functions. For example the HardwareSerial class can also use the extra functions of the Stream class.
It is done this way: class HardwareSerial : public Stream
The Serial object for a serial port is a real object in code. The Stream class is not.
The functions of the Stream class are in Stream.h.
Do you want to find either one of those bytes, or a sequence of the three bytes ?
You can search for the sequence with: mySerial.find( "\x01\x04\x04")
Hi Thanks yes i want to look for a sequence of three bytes.
Can you explain a litlle the syntax why this is \x01 and not 0x01 ?
Can you tell me how to understand difference between object and class ? I think to understand this more i should go deeper in C+ language isn't it ?
A class is a description of how it should look, the blueprint.
A object is the actual "variable" that has a memory location. It is not just a "variable" because there are also functions in it.
See for example the example sketch "sweep": https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
#include <Servo.h>
Servo myServo;
The "Servo.h" has the definition for the class here. It is accompanied by "Servo.cpp".
The line "Servo myServo
" creates the object "myServo" of the class "Servo".
It is the same as "
int data
", which creates the variable "data" of the type "int".
In the C++ language, a variable value can be a decimal, a hexadecimal, a binary, a character and maybe some more:
byte data = 1; // decimal integer
byte data = 0x01; // hexadecimal value
byte data = 0b00000001; // 8-bit binary value
byte data = 'A'; // Ascii value of 'A', which is 0x41
When a string is used, the so called "escape character" is a backslash.
char myText[] = "Hello World"; // Hello World
char myText[] = "Hello \x41 World"; // Hello A World
char myText[] = "Hello \x41 \"World\""; // Hello A "World"
There are explained here: Escape sequences - cppreference.com
Let's have some fun.
You know an array of 32 integers is this: int myData[32];
For a class it is exactly the same: Servo myServo[32];
Let's put those 32 objects in action: https://wokwi.com/arduino/projects/305336312628511297 (in the middle-upper of the screen is the start button).
Great thanks it's working well, and thanks for your explaination
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.