H
H
HiNester2021-04-02 14:38:06
Arduino
HiNester, 2021-04-02 14:38:06

How to accept Serial parameters on Arduino?

It is necessary to make the arduino accept the code and display the pixel on the display. The display requires 3 parameters: XY and true/false to be enabled. turn off the pixel. How to make reading these parameters into 3 variables? For example: /set 12 34 - will set print(12, 34, 1); And /clr 32 43 - will set print(32, 43, 0); I have already done the reception of the line, it remains only to divide 1 line into 2 variables, and /clr /set will set 1 or 0. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-04-02
@freeExec

scanf

K
Konstantin Zaitsev, 2021-04-02
@KonstantineZ

I was making a command line whose syntax is variable value

spoiler
int i = inputString.indexOf(" ");//Разделитель строки на подстроки
    if (i > 0) {
          String command = inputString.substring(0, i);
          String paramString = inputString.substring(i + 1, inputString.length());
          unsigned long param = paramString.toInt();
          Serial.print (command);
          Serial.print (" = ");
          Serial.println (param);
          //Здесь можно чтото сделать с переменными command и param, например, разобрать через switch-case
    }
    else Serial.println (F("Error: not value"));

In your case, you need to break it into three parts, i.e. param from my example break down again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question