Questions tagged [functions]

Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program.

Filter by
Sorted by
Tagged with
3
votes
1answer
52 views

Why no brackets after Interrupt routine inside attachInterrupt

I'm just curious as to why there are no brackets at the end of the ISR when attaching and assigning the interrupt command? attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE); ... ...
0
votes
1answer
30 views

CPP Function param use function with multi params [closed]

I want to specify a function with parameters for a function parameter, but it doesn't come together. //////////////////////////////////////////////////////////////////////// // Example funch... void ...
1
vote
0answers
32 views

Arduino PID Library

I hope you're doing well. I have some questions regarding the PID functions. Can you please explain to me the following commands? I shall be very thankful to you. PID myPIDX(&InputX, &OutputX,...
0
votes
2answers
68 views

How to reset a variable just before entering a function? [closed]

I am facing a problem where the if condition in the function waterNowrun is able to execute once after the program starts as the variable v is 0 at the start, but upon starting it again the if does ...
0
votes
1answer
58 views

Understanding the meaning of '[](){ /* Code */ }' in an argument

I have this piece of code from a library and im trying to understand the 3rd argument, I've searched google to the best of my abilities and could not find any tutorials or references in in the C/C++ ...
1
vote
1answer
61 views

Using functions in header files [closed]

I want to include a function in my sketch I moved to a .h file. I did it as follows: My code: #include "header.h" void setup() { fct(); } void loop() { } My header: #include "...
0
votes
1answer
83 views

Can you create an array for functions? [closed]

Let's say I want to create 10 functions, named Function1, Function2 until 10. Each function is used if a certain variable is equal to its number. Rather than using individual functions, I was ...
0
votes
1answer
36 views

This website in Arduino lists language references like functions and structures. What makes structures there different from functions?

https://www.arduino.cc/reference/en/ Language Reference Arduino programming language can be divided in three main parts: functions, values (variables and constants), and structure. functions For ...
1
vote
2answers
59 views

Arduino - Function -> return Cstr instead of string

I have following function for my Arduino: String readLine() { String received = ""; char ch; while (myFile.available()) { ch = myFile.read(); if (ch == '\n' or ch == '\r') { ...
1
vote
1answer
72 views

Doing several things at the same time with functions, objects or interrupts?

First of all, thank you for taking the time to read this. I am a newbie, so apologies (done examples on arduino website, basic C++). I'm trying to get an idea of what the best way to structure a ...
1
vote
1answer
34 views

Receiver sleep mode RDA5807M

Good afternoon guys! I have a radio receiver connected to an arduino and I want it not to work all the time, but to turn on by the arduino timer for a certain time, and the rest of the time the ...
0
votes
1answer
51 views

Error Compiling for board Arduino Nano while using Adafruit GFX

Whys is this happening to me?? I have to meet a deadline please help!! Here is my code. #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h&...
2
votes
1answer
129 views

What is touch_pad_get_status() supposed to return?

What I want to do: I have 7 touch buttons on my board (ESP32 TTGO T-Display) and I want to attach interrupts to everyone, calling the same function. In this function I would like to use ...
0
votes
1answer
100 views

How to use this confing function

For INA3221 current sensor, I found this library, however, I don't understand how to use the INA3221SetConfig() function as defined in the .cpp file link. void SDL_Arduino_INA3221::INA3221SetConfig(...
0
votes
2answers
328 views

Problem with a function having a parameter with a default value

I've got a problem using a default value for a function parameter. This code gives "'blink' was not declared in this scope": void loop(void) { blink(12, 2, 1000); } void blink(const ...
1
vote
0answers
40 views

Peculiar relay behavior from POST

I am trying to toggle on/off between two separate HTTP request. One submit button to turn it on, and another separate submit button to turn it off. I expect the device to launch in the off/low 0V ...
0
votes
3answers
211 views

Run multiple function with different argument/return structure by one function pointer

Edit: I tried a simple code in Arduino IDE which should've done in the first place instead in doing it in a desktop compiler. Because the results are different by experiment. In the desktop C compiler,...
2
votes
2answers
51 views

How to move a servo with a function

Im currently moving a servo from one side to another by using the typical for loop like this: int lightON = 180; int lightOFF = 90; if (buttonState == HIGH) { digitalWrite(LED, HIGH); for (pos1 =...
1
vote
1answer
151 views

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

I have two microcontrollers talking to each other using serial UART pins. Now for some reason which I can not figure out why... doing a Serial.print() does not work in an "if" statement. And ...
2
votes
1answer
33 views

Input state is stuck HIGH when function called using input also uses same input to call another function

I'm writing a choose-your-own-adventure style project for a class project. My Arduino Uno is set up with a 16-digit LCD display and two pushbuttons with pulldown resistors. I'm wanting each function ...
2
votes
1answer
22 views

Serial doesent work when calling function from timer

You can try the code on your arduino UNO to better understand what is hapening in serial monitor! I want to calculate jacobian matrix from rotation matrix! float jakMATB[3][3] = { {0, 0, 0}, {0, 0, 0},...
1
vote
1answer
247 views

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

Sorry i am a beginner and amateur when it comes to coding, can somebody help me to make the code inside the loop() less "monkey-like" by using a proper function? I have tried a lot and at ...
0
votes
1answer
101 views

Passing a time_t array as a function parameter

I'm trying to log reconnections and disconnections of a network. For that I've created 2 time_t arrays to store such occurances: const int logSize = 10; time_t conLog[logSize]; time_t disconLog[...
4
votes
1answer
643 views

How to get variable from callback function?

There is a library davetcc / IoAbstraction. The only library working as expected with my rotary encoder. The problem that on rotation I can only see serial output with position data, but I cannot get ...
0
votes
1answer
21 views

A word after function arguments braces

I'm just reading through a header files for task code in ESP8266 SDK. I found this line and wondering what does the word PRIVILEGED_FUNCTION after the function arguments braces means ? void vTaskDelay(...
1
vote
2answers
689 views

How do you remove an item from array arduino?

Is there a way that can change {3, 5, 3, 6} to {3, 5, 6} with a function? I checked all the arduino forums but they don't give the answer i need (just delete 1 item from an array with a function like ...
1
vote
3answers
152 views

Formatting variables from a variadic function

I have a function that concatenates a print line, however I am having trouble getting some of the strings to format correctly. Using Serial.print formats the output from keypad.getKey() correctly, ...
0
votes
1answer
160 views

Error taking address of temporary array when passing compound literal array

I have an Arduino sketch that passes an array into a method as a compound literal, but for some reason I keep getting the following error: void setup() { } void printConcatLine(char chunks[][20]) { } ...
0
votes
0answers
72 views

Tapered log potentiometer to linear formula

I have a tapered log 10K potentiometer. I would like some function which returns tapered log value to linear values. The potentiometer is a slider. When connected to the Arduino the wiper displays the ...
0
votes
2answers
73 views

Why is function mentioned in global declaration?

I came accross this code for writing data into EEPROM in arduino. Why is void printTemp();, void clearEEPROM(); and void writeTemp(); functions are mentioned in global declaration? How will this help? ...
5
votes
1answer
636 views

What does []() argument in function mean?

I am working in ESP8266 AsyncWebserver library and have been using this [](parameter) as an argument to some functions as shown below but does not really know what it means. Being a neophyte I am ...
0
votes
1answer
52 views

Boolean function call with character pointer input - dont understand how to get updated pointer value

Thank you for everyone's help in trying to find a solution. This library I'm working with was prewritten and is one of the most buggy hardware libraries I've had the misfortune to use. I have now ...
0
votes
3answers
48 views

problem using one function to blink different leds

I wrote a function to blink an led using millis and want to blink multiple leds with the same function but with different delay intervals. When I call this function thrice to blink 3 different leds, ...
2
votes
1answer
122 views

Remove blocking delay() toneMelody function?

I would like to change the delay() into a nonblocking function in the code below. I've implemented it (a part of a tutorial from arduino.cc) in my code, but the delay() is blocking the rest of my code....
1
vote
0answers
20 views

How to properly pass struct as argument? [duplicate]

This is my first question! i'm sorry if i'm doing something wrong. I'm trying to write a code that blinks some leds, but i cant quite work out how to use structs as arguments. This is the code: void ...
1
vote
1answer
60 views

Running commands from string

I have a string: string s="digitalWrite(8,LOW);" Is there any way to run it as a code?
0
votes
1answer
57 views

Function pointers that call one function

I'm reading a library file timer.h for STM core library that I just installed in Arduino hardware folder. Of course, there has to be a lot of questions for me as a beginner about many approaches/...
1
vote
2answers
419 views

7-Segment Display with WS2312B and FastLED

I thought of the idea of using the WS2312B LED strip to drive a custom 7-Segment display. The project will require a large number of these displays, and driving them with a single Arduino (I'm ...
0
votes
1answer
1k views

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

I am trying to invert the color of my OLED display screen once a button is pushed. I have the button situation figured out but I can not find a function that inverts the color. I am using these two ...
1
vote
1answer
312 views

Function to control servos

I'm trying to control 6 servos while writing a lean code. I think the function call isn't correctly yet and I think that the variables (pos_n, open_n, servo_1) in the for loop do not get inserted, but ...
1
vote
0answers
72 views

Get value from protected member of class

i'm really new to Arduino. I have Arduino Mega, a USB host shield and a barcode scanner. I'm using this library >> link and modified it example so barcode scanner worked (Got it from here) to read ...
0
votes
1answer
88 views

Protecting variables and functions within a library that has no class

If you want to have functions within a library that only the library itself should be able to use or variables that shouldn't be accessed from outside, you usually make them private by writing this in ...
0
votes
1answer
34 views

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

When passing an array to a function, you usually pass the length of the array along with it. You can compute the size of the array with sizeof(myArray)/sizeof(myArray[0]), which works just fine. ...
-1
votes
1answer
93 views

Trying to create a delay function whilst performing other functions, using Timer.h libraries. Arduino uno

I am having a compilation error saying invalid useof template-name 'Timer without an argument list.
1
vote
4answers
604 views

How do arrays work?

It's been days now I'm trying to figure out how arrays work in Arduino IDE. For better understanding, I assembled some pieces of code I found here and there to write this sketch: #define arrayLength(...
2
votes
4answers
358 views

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

Many arduino functions return -1 if something 'fails'. Serial.read for example returns -1 or the infamous ÿ when this function is called while the serial buffer is empty. As embedded C progammer, I ...
0
votes
1answer
39 views

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

Can Arduino handle variable variables? function getLetterCode(char input) { int letter_a = 17; int letter_b = 42; int letter_c = 50; return letter_$$input$$; //pseudocode } This is ...
0
votes
1answer
923 views

How to return Char Array Value in Arduino IDE Function?

Function char* getConnectDetail(int starting){ String data; for(int i=0;i< 1024 ;i++) { if(EEPROM.read(i+starting) != 0){ data += char(EEPROM.read(i+starting)); } } int ...
2
votes
1answer
4k views

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

Analyzing this and this answers under Arduino, which should be the proper way to pass a 2D array into a function? The function should be applicable to different sizes of 2D arrays. // NOT COMPILING ...
1
vote
2answers
2k views

How can I pass multiple variables to a function? [closed]

Using the FastLED library, I want to light up multiple lights at once. Currently I am passing in just one light to the function. spell( int LEDNumber ) { FastLED.clear(); leds[LEDNumber] = ...