Skip to main content

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
0 votes
2 answers
101 views

I am using an Arduino r4 Wi-Fi to control unique angle settings for two different servo motors during the execution and operation of a device I am building. I want to have the servos use different ...
user1363363's user avatar
1 vote
0 answers
973 views

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 ...
Mars's user avatar
  • 39
4 votes
1 answer
171 views

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 ...
Katie Neeley's user avatar
1 vote
1 answer
603 views

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 ...
Libegria's user avatar
-1 votes
1 answer
705 views

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 ...
Libegria's user avatar
0 votes
1 answer
4k views

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 ...
Zaffresky's user avatar
  • 183
0 votes
1 answer
146 views

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 ...
Dave's user avatar
  • 11
-1 votes
2 answers
1k views

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 ...
mehmet's user avatar
  • 297
3 votes
1 answer
118 views

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); ... ...
Diesel's user avatar
  • 144
0 votes
1 answer
87 views

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

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,...
John C.'s user avatar
  • 21
1 vote
2 answers
993 views

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 ...
Coder9390's user avatar
  • 512
1 vote
1 answer
2k views

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 "...
Spyro 999's user avatar
1 vote
1 answer
996 views

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 ...
AndroidV11's user avatar
0 votes
1 answer
60 views

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 ...
AndroidV11's user avatar
1 vote
2 answers
1k views

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') { ...
sharkyenergy's user avatar
1 vote
1 answer
203 views

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 ...
Zhelyazko Grudov's user avatar
1 vote
1 answer
114 views

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 ...
Антон's user avatar
0 votes
1 answer
287 views

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&...
Shrie Sharma's user avatar
2 votes
1 answer
383 views

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 ...
Ruvian de Césaro's user avatar
0 votes
1 answer
252 views

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(...
Zaffresky's user avatar
  • 183
4 votes
2 answers
5k views

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 ...
MichelBen's user avatar
1 vote
0 answers
61 views

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 ...
brad's user avatar
  • 201
0 votes
3 answers
1k views

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,...
R1S8K's user avatar
  • 283
3 votes
2 answers
307 views

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 =...
Marcelo_M's user avatar
  • 121
1 vote
1 answer
249 views

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 ...
S To's user avatar
  • 11
2 votes
1 answer
84 views

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 ...
Snyper's user avatar
  • 41
2 votes
1 answer
49 views

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},...
boki's user avatar
  • 31
1 vote
1 answer
341 views

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 ...
Baka's user avatar
  • 11
0 votes
1 answer
360 views

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[...
guyd's user avatar
  • 1,049
4 votes
1 answer
3k views

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 ...
max5555 max5555's user avatar
0 votes
1 answer
38 views

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(...
R1S8K's user avatar
  • 283
1 vote
2 answers
8k views

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 ...
Nobert's user avatar
  • 11
1 vote
3 answers
869 views

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, ...
VerySeriousSoftwareEndeavours's user avatar
0 votes
1 answer
474 views

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]) { } ...
VerySeriousSoftwareEndeavours's user avatar
0 votes
0 answers
572 views

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 ...
user66825's user avatar
0 votes
2 answers
106 views

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? ...
Amrutha B V's user avatar
3 votes
1 answer
1k views

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 ...
Mr.B's user avatar
  • 57
0 votes
1 answer
157 views

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 ...
AidenDawn's user avatar
0 votes
3 answers
100 views

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, ...
Zaffresky's user avatar
  • 183
2 votes
1 answer
414 views

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....
Joost's user avatar
  • 75
3 votes
0 answers
23 views

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 ...
Dariem Fabián Hidalgo Arias's user avatar
1 vote
1 answer
185 views

I have a string: string s="digitalWrite(8,LOW);" Is there any way to run it as a code?
rktech's user avatar
  • 23
0 votes
1 answer
195 views

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/...
R1S8K's user avatar
  • 283
1 vote
2 answers
1k views

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 ...
MDChaara's user avatar
  • 207
1 vote
1 answer
7k views

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 ...
Santiago Restrepo Serna's user avatar
1 vote
1 answer
745 views

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 ...
Vincent's user avatar
  • 13
1 vote
0 answers
141 views

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 ...
Pnzy's user avatar
  • 11
0 votes
1 answer
363 views

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 ...
LukasFun's user avatar
  • 295
0 votes
1 answer
1k views

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. ...
LukasFun's user avatar
  • 295