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.
67 questions
4
votes
2
answers
5k
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 ...
4
votes
1
answer
171
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 ...
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 ...
3
votes
1
answer
118
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);
...
...
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 ...
3
votes
2
answers
307
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 =...
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 ...
2
votes
1
answer
383
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 ...
2
votes
4
answers
938
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 ...
2
votes
2
answers
7k
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
1
answer
84
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
8k
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 ...
2
votes
1
answer
258
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(...
2
votes
1
answer
49
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},...
2
votes
1
answer
414
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....