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.

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
1 answer

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 device, "LIDAR-Lite" and my goal here is to op-check…
4
votes
2 answers

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 uint8_t led, int num, const uint16_t l = 12) { …
MichelBen
  • 51
  • 1
  • 4
4
votes
1 answer

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 these data as some variable value. There is the…
3
votes
1 answer

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); ... void blink() { state = !state; } In,…
Diesel
  • 144
  • 6
3
votes
2 answers

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 = lightOFF; pos1 <= lightON; pos1 += 1) { …
Marcelo_M
  • 121
  • 1
  • 7
3
votes
1 answer

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 curious to know what does this convention means, its…
Mr.B
  • 57
  • 1
  • 8
3
votes
0 answers

How to properly pass struct as argument?

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 setup(){ pinMode(2, OUTPUT); pinMode(3,…
2
votes
1 answer

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 touch_pad_get_status() or other to get which button was…
2
votes
1 answer

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 to display text on the LCD and then take two user…
Snyper
  • 41
  • 4
2
votes
1 answer

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}, {0, 0, 0} }; float POKUS = 0; float k =…
boki
  • 31
  • 2
2
votes
1 answer

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. Can anyone help me to change this? void…
Joost
  • 75
  • 1
  • 1
  • 6
2
votes
4 answers

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 am personally a fan of letting functions return…
2
votes
1 answer

Cannot convert 'int (*)[size]' to 'int**'

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 EXAMPLE void f(int** x,const int m, const int…
Brethlosze
  • 337
  • 1
  • 4
  • 17
2
votes
2 answers

How can I pass multiple variables to a function?

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] = CRGB (255,255,255); //white FastLED.show(); time =…
Joshua Dance
  • 141
  • 1
  • 6
2
votes
1 answer

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(int var){ #if KEYDEBUG //Assert …
Brethlosze
  • 337
  • 1
  • 4
  • 17
1
2 3 4 5