Questions tagged [variables]

Variables are used to store data in a sketch/program.

Filter by
Sorted by
Tagged with
0
votes
4answers
3k views

Wemos D1R2 - Onewire 2 DS18B20 passing to variable

I'm a beginer, did some tests with Uno and now have a Wemos D1R2 on my hands... I'm building a sort of weather station that will send data to thingspeak.com and log this data there. I managed to ...
-1
votes
0answers
36 views

Variable not updating from inside IF? Ardunio. Uno

First time poster long time leecher. I'll try to edit this best as possible in a moment... Code takes DHT22 data, displays on LCD, push buttons to adjust a setpoint variable (rhset) then uses ...
0
votes
1answer
43 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
1answer
43 views

Scope of RtcDateTime object when declared outside of a function

I'm trying to merge 2 Arduino samples, in order to be able to use DS3231 RTC module with ESP8266 WiFi simple web server. My RTC library is this: https://github.com/Makuna/Rtc/wiki Generally, to code ...
0
votes
1answer
27 views

Using the same variable between if-statements within loop()

I wonder if there is a good way to use the same variable value between two different if-statements within the loop(). Within the Servomotor section of the code, I want to use the value from the first ...
0
votes
1answer
73 views

Sorting voltage data from pin A0 to 3 variables (ranked)

I don't have any code for this yet but I would like some ideas on coding it. I have a directional antenna that is rotating at a slow speed and a ham radio connected to the antenna. I have an output ...
0
votes
1answer
20 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 ...
6
votes
1answer
2k views

What are the benfits of global variables over static class members?

On an embedded system we use global variables often to keep dynamic memory consumption on heap and stack low. But global variables are also considered bad programming practice if they aren't used in a ...
0
votes
1answer
51 views

Variable sets to 32767 - MATLAB Arduino

I am running out of ideas of what may be causing this problem, and I would appreciate some help identifying anything I am overlooking. Quick Problem Summary A variable gets set to 32767 quite often ...
0
votes
1answer
37 views

How to merge two GPS coordinates without losing decimals

I want to take the GPS coordinates like 42.1234 per 22.1234 and merge them as a string, with a separator character: 42.1234 x 22.1234 But using this code: gps_string = (String)gps.location.lat()+' ...
1
vote
4answers
131 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(...
0
votes
2answers
305 views

How to display float variables on oled display (0.96'')

I have a similar problem than the discussed here : How to display variables on 0.96" OLED with u8glib library? I'd like to know how can I show float variables in place of int variables. What ...
0
votes
2answers
26 views

How to make procedures triggered remotely

I am installing lights in a model train and there are multiple prototypical lighting procedures that need to be activated. The lights are connected as follows: Headlight Top - Pin 1 Headlight Bottom - ...
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 ...
3
votes
2answers
3k views

How to pass variables to custom callback functions

I want to use the Ticker library of the ESP8266 Arduino core to (asynchronously) delay the switch of a pin to a desired state like below. I am not sure about the "here is" function definitions and I ...
0
votes
0answers
30 views

How to create parametric variable in class decleration

I hope the subject of this question if correct. in timeOUT constructor, 3 more instances of other class are defined: endTimeOUT_inFlash(key1), inCodeTimeOUT_inFlash(key2), updatedTimeOUT_inFlash(...
1
vote
1answer
654 views

I2C wire.h send 2 variables

I am trying to send 2 variables with wire.h. I tried with this code: MASTER RECEIVER: #include <Wire.h> // include la libreria #include <LiquidCrystal_I2C.h> #include "RTClib.h" ...
0
votes
0answers
30 views

Accel Multi Stepper - Array for timelapse operation

I am trying to run 2 cameras for timelapse. I can do this with a single stepper: void doSteps(long steps) { calcSpeedStepper(); digitalWrite(sleepPIN, HIGH); stepper1.setCurrentPosition(0); ...
0
votes
1answer
4k views

Saving a .txt file to SD Card and Reading each content data to txt file then save it to a variable

I am new to arduino I am trying to create an arduino project that Saving a .txt file to SD Card and Reading the txt file then save it to a variable data type "Long" named 'savednum'. I had ...
0
votes
1answer
233 views

Accelstepper - how to switch from fullstep to halfstep in loop?

I am using Accelstepper library to control a unipolar stepper motor. In my project, I would like to run the stepper in full-step mode when I need speed and in half-step mode when I need precision. As ...
0
votes
0answers
202 views

string.charAt() is not returning the correct value

I know this is a super basic question, and I did try debugging, but somehow I think I am missing the way variable stores value in Arduino. int enablePin = 2; // ebanble pin for slave String ...
0
votes
2answers
105 views

Run piece of code based on a feature

I am an engineering student completely new at using Arduino so my following question might be silly but still. I do not think you'll need to get the entire code so I am only going to expose the idea. ...
0
votes
1answer
160 views

what is the difference between array of uint16_t data versus an array of uint16_t variables?

I've been struggling with weird behavior, crashes and general problems when trying to use an array of four uint16_t groups of data. When I create four separate variables and load that into an array, ...
24
votes
4answers
4k views

Why use an int variable for a pin when const int, enum or #define makes much more sense

Why do people use a variable to specify a pin number when the pin is unlikely to change throughout the execution of the code? Many times I see an int being used for a pin definition, int led = 13; ...
0
votes
3answers
164 views

I want to reset a variable after each 1 second on an Arduino

I want to reset this counter variable which I created after each 1 second, but I don't want to disturb the if statement. Here is the code: int button=A0; int val; int count=0; int presss; void ...
0
votes
2answers
193 views

Assigning formatted value to variable

Look at this snippet of code (from TinyGPS++ library): Serial.print(gps.location.lat(), 6); It prints the latitude location with 6 decimal points. I want, instead of printing that value, to have it ...
18
votes
4answers
133k views

How can I declare an array of variable size (Globally)

I'd like to make three arrays of the same length. According to the documentation, Arrays must be defined as int myArray[10]; where 10 can be substituted for a known length (another integer), or filled ...
2
votes
3answers
569 views

Global or local

I'm new to Arduino and embedded, but understand that it is often better to use global instead of local variables (such as here or here). I have this simple code (from here): //Libraries #include <...
8
votes
2answers
29k views

How to retrieve the data type of a variable?

I am using Arduino and I would like to know if there is a function that returns the data type of a variable. That is, I would like to run something as like the following: // Note: 'typeof' is a ...
0
votes
1answer
48 views

What is the easiest way to count how many global variables are in your sketch code?

I have a fairly complicated sketch with about 1k lines of code. I should also say that I'm not a programmer by trade... As I go over my code and try to make it more efficient, it'd be good to know ...
0
votes
2answers
185 views

Make a float using integers [closed]

I want to make a floating point number that has only one decimal point. I have separate integers for both side. Ex: int n1 = 8; int n2 = 2; I want to make 8.2 as float value using separate ...
0
votes
1answer
40 views

What do the charactors “ '/2' ” mean in the variable declaration?

I'm working on an RS485 project, In the CPP file there are const variables declared in the following manner: #include <RS485_protocol.h> const byte STX = '\2'; const byte ETX = '\3'; What ...
0
votes
2answers
95 views

Assigning array variables to int variables

I need to control thousands of rgb leds.To make animations I want to assign led numbers(addressable led strip) to arrays.For example floor[2]room[14]=106 106 is the number of led,there are many floors ...
0
votes
1answer
87 views

Global Variable does not Change when Value is set within Boolean Function

I have a boolean function which contains a string. In my main project this string is extracted from a website using an ESP8266 which is compatible with the Arduino IDE. I need to convert this string ...
2
votes
2answers
7k views

'content' is not captured

I try to make a variable that can be modified from the server, using and ESP8266. #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <...
1
vote
1answer
55 views

How to deal with this array correctly?

I am using a led strip WS2812b, an ESP8266 (NodeMCU 1.0) and a gesture sensor APDS9960. I want that when I move my hand from left to right and from right to left I change the colors of the strip of ...
0
votes
1answer
46 views

Hex output although I always define integer

Code below is to read 4 thermometers and use values to turn on or off the heaters (I'm stuck at reading). I'm reading and displaying temperature very well, but it comes to the problem, where I want ...
0
votes
3answers
354 views

Do some variables not hold their value when a while loop is exited?

Sorry if i'm asking too many silly questions but i'm really stumped on this one. I understand if I set a variable inside a loop that that variable won't be within scope from the outside of the loop. ...
0
votes
1answer
27 views

Variable that holds the users input doesn't empty itself, so the program only works once

This code seems to function, but only works once before I need to press the reset button. Otherwise, it repeats the same error message. It might have something to do with emptying the String variable. ...
4
votes
2answers
786 views

Locally declared variable takes up global variable space in dynamic memory/SRAM

I'm trying to make my Arduino Uno control the air conditioner by recording the raw IR signal of several of the AC remotes temperatures using AnalysisIR. However these IR codes are quite long (array ...
0
votes
1answer
89 views

warning: variable 'b' set but not used

I got the following error: warning: variable 'b' set but not used. I think I do a really small thing wrong but I can't figure out what it is. #define array_size(array) ((int)(sizeof(array) / sizeof(...
3
votes
6answers
11k views

When is it necessary to use “float” instead of “int”?

I'm very new to Arduino and I am making a code for a pedometer. I have a lot of variables and I have used "int" multiple times, but I just came across a code with "float". Now because my coding ...
0
votes
1answer
185 views

Arduino variables loaded from SD card

I am trying to load some variables from an SD card on the start up of my arduino Uno. I have been given some advice but am unable to communicate at the same hours. Using this advice, I have the ...
0
votes
1answer
252 views

Is there any way to group variables like group.variable as you can in Java/Delphi

I'm writing a sketch which does some calculations on measured variables, and it's based on a similar program written in Java like c = A.Ux + B.Uz; Where A&B have various parameters Ux,Uy,Uz etc In ...
-1
votes
1answer
180 views

Arduino - use print(.., DEC) to save into variable

I am using: Serial.print(rawCodes[i - 1], DEC); to print into serial monitor, but how can I save (rawCodes[i - 1], DEC) to save into variable?
0
votes
2answers
45 views

Question about Variables [closed]

is there a way to use a previous assigned value to variable to adjust the step motor? what i mean is: example: Sensor reads 100 degrees so Adjust the step motor to 100 degrees and hold, then after ...
1
vote
4answers
2k views

Send serial command and wait for reply

I am new to Arduino and have tried all kinds of code for attempting to achieve this. None with any luck, however. I feel that it should be a relatively easy task and therefore, figured that someone ...
1
vote
2answers
537 views

How can I declare global array with its length stored in EEPROM?

I am working with Arduino UNO connected with BV4612 display. I am working on a simple code that controls several water pumps. Each pump has several modes it can run in. I store these modes in an array....
0
votes
1answer
4k views

Best way to assign value to lot of variables

I'm building web based remote control system for esp8266. In arduino IDE, using the ESP libraries. To, send data to the server, I'm using http post. For some settings, I need to transfer 30 or so, ...
1
vote
1answer
2k views

Arduino resets variable every loop

im new to arduino and have a problem currently with my project on sun tracking. The problem is that every loop it resets my variable back to 1 or whatever i set it. I have 4 photodiodes working ...