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
2answers
38 views

Why is function mentioned in global declaration?

I came accross this code for writing data into EPROM in arduino. Why is void printTemp(); void clearEEPROM(); and void writeTemp(); functions are mentioned in global declaration? How will this help? #...
5
votes
1answer
590 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
35 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
42 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, ...
0
votes
1answer
68 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 ...
0
votes
1answer
38 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
43 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
94 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
108 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 ...
0
votes
1answer
88 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 ...
0
votes
0answers
34 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
25 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
25 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
56 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
254 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
183 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
35 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
287 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 ...
1
vote
1answer
924 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
242 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] = ...
2
votes
1answer
37 views

Remove Function at Preprocessor Time

I have a single function for debugging messages, used through all the project. When KEYDEBUG is defined as 1 or 0, the function is enabled or disabled as required. #define KEYDEBUG 0 void debugging(...
0
votes
2answers
141 views

can't return float value from function

I want to put a 2 seconds delay to temperature reading but the millis() delay is not applying. #include <OneWire.h> #include <LiquidCrystal_I2C.h> #include <DS3231.h> #include <...
1
vote
2answers
93 views

Fail to return int value from a function

I have created myJSON library to simplify read and write values from/ to FLASH of my ESP8266 NodeMCU/ Wemos Mini. I do not want to "mess up" the question, posting my entire code/ library - but to try ...
0
votes
1answer
55 views

Strange artifact in writing to serial while executing loop

Hope you can see this. https://gist.github.com/DevilWAH/60ad144d2858f53845ac2e80f84bb070 The main file in this is "morse-led-rfid" which is taking reading data of an RFID tag and then displaying ...
0
votes
2answers
91 views

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

I'm trying to create a function that enters a key/value into a JSON file. But, since value can be an int or char, I don't want to create 2 functions for each type. Is there a way ? void setValue(...
0
votes
1answer
63 views

Random without parameters

During a programming contest, I used the following line of code: symbols[i] = random() & 0b11; After the contest, when I looked into the Arduino reference, I found out random takes one or two ...
0
votes
2answers
85 views

How to write a function to return matrix?

I need a function to return a 2x2 rotation matrix, something like: float matrix(float phi){ float R[2][2] = { {cos(phi), -sin(phi)}, {sin(phi), cos(phi)} }; return R; } But ...
0
votes
1answer
189 views

Problem with String& argument of a function

I am trying to send SMSs using a GSM module with Arduino Mega. I have followed a tutorial and downloaded the SIM908IDE100 library. I am using the function SendSMS(String&, const char [27]);. It ...
0
votes
2answers
96 views

Initializing variables of a function [closed]

By playing with some examples I found the following construct: void Show(int nav = 0) // -1 top, 1 bottom and I wondered what effect it has to initialize the handover parameters in the function ...
1
vote
1answer
629 views

Passing arrays, global arrays within functions, pointers, and declaring array sizes

I'm super confused right about now! I've been working on project involving Xbees in API mode, and I need to send different arrays of bytes to the Xbee depending on which buttons I press. Mostly what ...