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
0answers
8 views

Arduino test pin and store or return result; help convert working function to library

I created an Arduino compatible checkDevice() function for a circuit designed to enable detecting devices that are plugged in. Essentially testing if a pin is HIGH or LOW and storing up to 8 boolean ...
1
vote
2answers
39 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
42 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
52 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
23 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
21 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
24 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
40 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
168 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
104 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
219 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
373 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
113 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
80 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
86 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
53 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
84 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
55 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
55 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
135 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
85 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
469 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 ...