7

That is called a lambda expression and it's a way of including the content of a function as a parameter anonymously instead of writing an actual function and using the name of it. It's shorthand for: void myCallback(AsyncWebServerRequest * request) { // some code....; request->getParam("Param1")->value(); } // ... server.on("/page", ...


7

It's just a failing of the Arduino build process to generate prototypes (function declarations) for functions that have default argument values. There's otherwise nothing wrong with what you're doing. Not in my opinion anyway. The build process sometimes chokes on function or class templates as well. The answer to these sorts of problems is probably that ...


5

High likely you are exceeding your character array, see: char a[5]; Which can hold 5 characters. However, you write: if(strcmp(a,"RGB_1") == 0) Which assumes you receive "RGB_1" which is 6 characters, because a string ends with a 0. What also might happen is that you indeed receive only 5 characters without the ending newline, which ...


4

This is (unfortunately) not an Arduino question. It is actually about the syntax of C++ which is a rather complex language. The mechanism you have discovered is called default arguments. The function prototype or definition may contain the default values of the arguments. As this is a list the default values are restricted from right to left. It is not ...


4

Callback functions are usually void and don't return real data, because they are called by some type of event handling system, like the mentioned library. As this is calling the callback function, not you, it does not make much sense to return data from it. To get that return value, you would need to change the library for every bit of data, that you want. ...


4

The question is somewhat confused, but I think I got what you mean. Your code suffers from too much repetition. You only showed the handling of two selectors, but you want to handle 6 of them. Repeating all the logic 6 times would make the code unwieldy and hard to maintain. So you want to put the logic in a function and just call that function six times. I ...


4

As pointed out from people in the comments, things need to be different. If you use the function touchAttachInterrupt, things are a bit simpler. The example that comes with the ESP32 library is enough to make you understand. If you want to do what I did, this is how: touch_pad_init(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); touch_pad_config(...


3

This is actually pretty simple: if (s == "digitalWrite(8,LOW);") { digitalWrite(8,LOW); } Obviously, it will not work is s contains any other string... If you want something more general, that is able to interpret a wide range of possible commands, you will have to define a language, and write an interpreter for that language. From the example you give,...


3

I cannot assert anything for sure, as I was not involved in the design of the Arduino APIs. However, just like Elliot Alderson, I suspect this was inspired by the traditional C APIs. The manual page for getchar(), which is a very old function from the standard C library, states: fgetc(), getc() and getchar() return the character read as an unsigned ...


3

No, you can't do that sort of thing. That sort of thing is only possible on interpreted languages where the name of the variables is seen at runtime. In compiled languages you can't see the variable names (they no longer exist) so you can't access them by name like that. Instead you need to either store your variables in a simple array and access them by ...


3

BUZZER_NOTE notes[]; //-- Funny how the same declaration tried below DOES work if it's inside a class It doesn't really. C++ language prohibits that. It is just a non-standard quirk of GCC compiler used by Arduino IDE, which happens to support C-style flexible array members in C++ code. // BUZZER_NOTE notes[]; //-- Compilation error: Of course. You ...


3

According the prototype of f and the usage pattern for its x argument, the function expects this argument to be a pointer to the first element of an array of pointers to the first elements of arrays of int. However, the matrix in main() is defined as an array of arrays of int. If you try to pass this to a function, the matrix will decay into a pointer to an ...


3

I see 2 problems with your code: Returning a value from a function: If you want to return a value from a function, you will have to make sure, that in any case the return x statement is executed inside the function in the temperature() function you currently have this if statement: if(currenttime - checkTempinterval >= checkTemp){ Inside of it is the ...


3

the parameters of a function call are copied into parameters in the function. if the pointer is copied it still points to a memory where you write the data. if int is copied then changing the value changes the copy, not the variable used as parameter. reference is kind of pointer how to make an in-out parameter by passing a parameter by reference void ...


3

With the format "ci", the argument is interpreted as an integer, and the output is correct: 49 is the ASCII code of '1'. With the format "cc", the argument is interpreted as a string (pointer to an array of chars), which is incorrect. One (bad) solution is to use the "cc" format and pass &btnPressed as an argument. The problem with this approach is ...


3

I assume, that the fun_ptr points to the different service functions to do some kind of animation other other long running tasks on your display, thus you want to repeatedly call them in a structured way. What you are currently doing will not really work. When you call a function, you need to provide its arguments. That's the same for a function pointer. You ...


3

Without looking at the library, you can check yourself if this method (INA3221SetConfig) is called from the begin method (of the same class). Just trace back the methods manually until you find a call to this method. About the | or 'bit-wise-or' operator (see https://en.wikipedia.org/wiki/Bitwise_operations_in_C), these are used to set bits in a byte/word/...


3

An RTOS may be a good option for running a complex application on a quite powerful Arduino. Many Arduinos (the AVR-based ones), however, are too limited to run complex applications, and the overhead of an RTOS is quite significant for them. In this case you end up with two options: non-blocking programming interrupts Whichever is best depends on the ...


3

You cannot work with c-strings like with Strings. You need to use the standard c-string functions (like sprintf(), strcpy() and siblings) or directly access the char array. This gives the following problems with your code: See this line: char* received = ""; Here you create a pointer to a constant empty string. But this will NOT create a buffer,...


3

Here's an example of how to do it: jump_table.ino int func1(int arg) { return arg + 1; } int func2(int arg) { return arg + 2; } int func3(int arg) { return arg + 3; } int func4(int arg) { return arg + 4; } int func5(int arg) { return arg + 5; } int func6(int arg) { return arg + 6; } int func7(int arg) { return arg + 7; } int func8(int arg) { return ...


2

You cannot return an array from a function. There are several alternatives, though. One of them is to allocate the memory for the array within the function, as suggested by user2912328's answer. I would not recommend this approach though, for the reasons already stated in that answer. For an overview of the other possible options, see this response to the ...


2

Your problem is not directly how to return a variable, but how to give a variable from outsite the function as parameter to be filled by the function. There are basically 2 types how you can give a variable to a function: by value or by reference The definition of getINTValue() says getINTValue (const char *key, int retval) so retval will be an integer ...


2

In your code colors is declared as rgb_color colors[ledCount]; This means that the very first iteration of this cycle in shiftLED for (uint16_t i = ledCount; i > 0; i--) { // access colors[i] } will access ledCount[ledCount] which is obviously out of bounds (and will actually write into that location!). The behavior is undefined after that. Using ...


2

The short answer is “no, it's not possible”. You will have to use two different functions. These two functions can share the same name, using function overloading. You can even have the compiler write these functions for you, based on a template you provide, as shown in Juraj's answer. These language features help provide the illusion of there being a single ...


2

In C++ you can create a template function. (The ArduinoJson [] operator is a template too.) #include <ArduinoJson.h> StaticJsonDocument<512> tempJDOC; template <typename T> void setValue(const char *key, T value){ tempJDOC[key] = value; } void setup() { Serial.begin(115200); setValue("a", 5); setValue("b", "xyz"); ...


2

In your case you do not use the entire body, so you can use a macro. This way the code when KEYDEBUG is 0, will be like the complete function would not exist (except for the void cast, see below). #include "assert.h" #define KEYDEBUG 0 #ifndef KEYDEBUG #define debugging(x) void(x); #endif void debugging(int var){ assert(var); } void setup() { // ...


2

You may create a struct with "x" elements, one for each LED: struct ArrayOfBooleans { bool array[4]; }; ArrayOfBooleans myOutputArray; myOutputArray.array[0] = true; myOutputArray.array[1] = true; myOutputArray.array[2] = false; myOutputArray.array[3] = true; lightEmUp(myOutputArray); void lightEmUp(ArrayOfBooleans myOutputArray) { bool ...


2

There is a function that invert the colors of your screen, you can pick either black on white or white on black, I have tried it and I have quite experience with your display, I think you should try this piece of code. At the beginning of your Arduino code be sure that you declared the object using the same name. Adafruit_SSD1306 display(SCREEN_WIDTH, ...


2

I think you are totally misunderstanding, about variables and types and how using multiple servos with 1 function can work, and that this is your real question and not the thing with inserting variables (whatever you mean by that). You are trying to put together a string and use it as variable name. That does not work. A string is only a variable/instance ...


2

If your library is implemented in a single .cpp file, you can define these variables and functions within that file, and give them the static qualifier: static int my_private_variable = 42; static void my_private_function() { ... } Obviously, there should be no mention of them in the .h file. Note also that we are talking about global variables. ...


Only top voted, non community-wiki answers of a minimum length are eligible