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.
66 questions
1
vote
0
answers
787
views
Keyestudio KS5009 ESP32WROOM32 Smart Home
I'm encountering persistent errors with the sample code provided for my smart home kit project. Despite conducting extensive research and troubleshooting efforts, I haven't been able to find a ...
4
votes
1
answer
139
views
How do you take the simplest continuous reading from a Garmin Lidar Lite V4 using I2C on a Particle Boron v4.1.0?
Hey there Stack community.
I'm working with the Particle Boron v4.1.0.
I'm connecting a Garmin Lidar Lite V4 on I2C.
I'm using the LIDARLite_v4LED.h header file found in the library given for this ...
1
vote
1
answer
515
views
Round to first significant digit
I want to round a decimal number (x), but I need to do it differently depending on how it is. If it has integer significant digits, we round to the nearest integer, and if not, we round to the first ...
-1
votes
1
answer
614
views
parseFloat() function [duplicate]
I have noticed that the parseFloat() function returns decimal numbers, but only up to 2 decimal places. Would it be possible for it to return the numbers with more decimal places? In case we need more ...
0
votes
1
answer
4k
views
variable or field declared void Error
For a larger sketch, I have separated a chunk of code in a separate .cpp file
#include "msg.h"
#include <Arduino.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
void ...
0
votes
1
answer
103
views
Parallel I/O - maybe use Machine code function call
I'm a newbie to arduino but been programming lots.
I have a project where I would like to output 4 bits to adjacent pins and read 4 bits from another (4) adjacent pins. (Imagine a matrix keyboard ...
-1
votes
2
answers
1k
views
İs that possible to a function return String OR Int depends on address
Well, I'm trying to use a HMI display and this HMI storing datas in separeta addreses. Such as integers addr. is between 0x80000 to 0x9ffff and also for string's addr is between 0 to 0x1ffff.
At this ...
3
votes
1
answer
98
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
1
answer
71
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
0
answers
368
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,...
1
vote
2
answers
941
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 ...
1
vote
1
answer
2k
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 "...
1
vote
1
answer
873
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
1
answer
47
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
2
answers
1k
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
1
answer
187
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
1
answer
94
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
1
answer
235
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
1
answer
363
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
1
answer
217
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(...
3
votes
2
answers
4k
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
0
answers
50
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
3
answers
1k
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,...
3
votes
2
answers
275
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
1
answer
205
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
1
answer
61
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
1
answer
30
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
1
answer
311
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
1
answer
345
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
1
answer
3k
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
1
answer
33
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
2
answers
7k
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
3
answers
730
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
1
answer
456
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
0
answers
463
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
2
answers
84
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?
...
3
votes
1
answer
1k
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
1
answer
131
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
3
answers
65
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
1
answer
361
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....
3
votes
0
answers
23
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
1
answer
174
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
1
answer
182
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
2
answers
1k
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 ...
1
vote
1
answer
6k
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
1
answer
686
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
0
answers
126
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
1
answer
336
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
1
answer
1k
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
1
answer
251
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.