Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
1answer
22 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
31 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
98 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
85 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
34 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
81 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
110 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
74 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
35 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
65 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
75 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
52 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
78 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
33 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
45 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
72 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
81 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
277 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 ...