10 votes

Problem with a function having a parameter with a default value

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....
timemage's user avatar
  • 5,163
6 votes
Accepted

What does []() argument in function mean?

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: ...
Majenko's user avatar
  • 105k
6 votes
Accepted

Why no brackets after Interrupt routine inside attachInterrupt

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 ...
chrisl's user avatar
  • 16.1k
5 votes

Serial.print skips or hangs inside a "if" statement. Trying to call a function VIA serial uart

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" ...
Michel Keijzers's user avatar
4 votes
Accepted

Initializing variables of a function

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 ...
Mikael Patel's user avatar
  • 7,959
4 votes

What is touch_pad_get_status() supposed to return?

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 ...
Ruvian de Césaro's user avatar
4 votes

Can you create an array for functions?

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 ...
Alex Hajnal's user avatar
3 votes

Is there an Adafruit function to invert the colors of my screen for Arduino language?

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 ...
Shams M.Monem's user avatar
3 votes

Why do most arduino function return a -1 instead of a 0

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 ...
Edgar Bonet's user avatar
  • 42.7k
3 votes
Accepted

How to access variables by variable? (I.e. variable variables?)

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 ...
Majenko's user avatar
  • 105k
3 votes

How do arrays work?

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 ...
AnT stands with Russia's user avatar
3 votes
Accepted

can't return float value from function

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 ...
chrisl's user avatar
  • 16.1k
3 votes

How do you remove an item from array arduino?

There is no such concept in C. Arrays are a fixed size and that size can never be changed. You can't "delete" an entry. You can replace one with something else, and you can introduce the ...
Majenko's user avatar
  • 105k
3 votes
Accepted

How to get variable from callback function?

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 ...
chrisl's user avatar
  • 16.1k
3 votes

How do i improve this Code? (or how to pass a Char String into a Function to behave like a Variable)

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. ...
Edgar Bonet's user avatar
  • 42.7k
3 votes
Accepted

How to use this confing function

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 ...
Michel Keijzers's user avatar
3 votes
Accepted

How to reset a variable just before entering a function?

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 ...
jkp's user avatar
  • 174
3 votes
Accepted

İs that possible to a function return String OR Int depends on address

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.
Nick Gammon's user avatar
  • 38.1k
3 votes

How do you take the simplest continuous reading from a Garmin Lidar Lite V4 using I2C on a Particle Boron v4.1.0?

As romkey pointed out, I had the pull-up resistors wired wrong. Pull-up resistors are connected to power, not to ground. Then I had to include wire.h and initiate Wire.begin(); in setup.
Katie Neeley's user avatar
2 votes
Accepted

Is it possible that function will get a parameter that can be int OR char?

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 ...
Juraj's user avatar
  • 17.9k
2 votes
Accepted

Fail to return int value from a function

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 ...
Juraj's user avatar
  • 17.9k
2 votes

Fail to return int value from a function

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 ...
chrisl's user avatar
  • 16.1k
2 votes
Accepted

Strange artifact in writing to serial while executing loop

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] ...
AnT stands with Russia's user avatar
2 votes
Accepted

Remove Function at Preprocessor Time

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). #...
Michel Keijzers's user avatar
2 votes
Accepted

Cannot convert 'int (*)[size]' to 'int**'

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 ...
Edgar Bonet's user avatar
  • 42.7k
2 votes
Accepted

How can I pass multiple variables to a function?

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;...
tony gil's user avatar
  • 362
2 votes
Accepted

Compute the size of an array that was passed as a parameter to a function

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 ...
Majenko's user avatar
  • 105k
2 votes
Accepted

Running commands from string

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 ...
Edgar Bonet's user avatar
  • 42.7k
2 votes

Function pointers that call one function

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 ...
Majenko's user avatar
  • 105k
2 votes

Why is function mentioned in global declaration?

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 ...
Majenko's user avatar
  • 105k

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