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 ...


6

It is right, that you are putting brackets after the function name if you are calling it. But with attachInterrupt() you just want to give it the information, which function to call in case of an interrupt. With the brackets the compiler would think you want the function to be executed and the result/return value being given as parameter to attachInterrupt()....


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

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(...


4

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 ...


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

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

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

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. ...


3

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 ...


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

The purpose of the waterNowrun function and 'v' seems to be to turn on some water and keep it running for 10 iterations, before turning it off? I would split the waterNowrun into two functions: void waterOn() { Serial.println("Boo Boo"); digitalWrite(14, HIGH); Blynk.virtualWrite(V5, 255); lcdI2C.selectLine(2); lcdI2C.print(&...


3

is that possible to make two kind of return type for a method No. Functions are declared with a single return type. What is the point anyway of returning a blank string? You need to redesign.


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

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

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

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 ...


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

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 ...


2

You can't. You are passing a pointer to the array, and sizeof will give you the size of that pointer (2 on an 8-bit Arduino). Instead the normal way is to pass the size of the array as a parameter to your function. myFunction(myArray, sizeof(myArray) / sizeof(myArray[0]));


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

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,...


2

bb_perip is a function that returns a pointer to a bit from a register that is related to a specific timer peripheral (there's more than one). That pointer is then dereferenced with the * operator to make *bb_perip(...). What bb_perip returns is dependent on what timer you are using and what value you are interested in. bb_perip is not a pointer to a ...


2

Those are called function prototypes. They mean "These functions exist somewhere else". That "somewhere else" could be later on in the same file, or a different file entirely. Usually these kind of things are provided by header (.h) files, or are automatically created (for functions in the INO file) by the IDE and hidden from you, so you never really see ...


2

You can't with the Arduino. I am not quite sure why, but I think it may be because it's a Modified Harvard architecture machine. You can better achieve what you want with variadic arguments, however: void printConcatLine(int num, ...) { va_list ap; const char *s; va_start(ap, num); for (int i = 0; i < num; i++) { s = va_arg(ap, ...


2

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 ...


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