Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [variables]

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

0
votes
1answer
37 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
0answers
42 views

Global variables update then stop updating

I have an Arduino script used on a LeoStick to read weather data sensors and provide data via I2C when requested by a C program run on a BananaPro every 15 minutes. This setup has worked well for 18 ...
0
votes
2answers
49 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
27 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
58 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
17 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 ...
0
votes
1answer
45 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 ...
1
vote
1answer
29 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
40 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
55 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
2answers
89 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
24 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. ...
3
votes
2answers
474 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
40 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(...
0
votes
1answer
960 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
64 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
47 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
83 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
42 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
2answers
181 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....
1
vote
1answer
404 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 ...
0
votes
1answer
813 views

Call by reference

I am trying to learn 'call by reference'. I want to call a function fcn1 from the main loop and pass a reference of the local variable var to the function fcn1. Next step is to call a second function ...
-1
votes
1answer
28 views

variable doesnt have a type name

Why can't i assign the value to a variable outside the function? void setup(){} int a; a=12; // WHY IS THIS GIVING ME ERROR void loop(){ } Why the line a=12 gives me an error? Thanks!
-1
votes
3answers
72 views

Is there a way to put multiple integers in a method? [closed]

I'm working on a project that has 3 RGB LEDs. I want to make a simple method that I can call to control the LEDs for example: showColor(left, 255, 0, 50); Which would light up the left LED at 100% ...
0
votes
2answers
1k views

Fill an Array with Values

I have a function in which I change the pinMode on many of my Arduino's pins based on a passed in mode. I first construct an array of bytes specifying each pin to be an input or an output and then I ...
-1
votes
4answers
653 views

Global variable won't update inside void loop arduino

I need to update my global variable once I get a 'overdtrue' response and light up my LED but only my LED is lighting up but my global variable is not updated. Here is my code int x = 0; void loop()...
0
votes
1answer
297 views

Why using static volatile for variables and only static for arrays in TWI library?

I want to know why to declare variables with static volatile and arrays with only static in TWI library? For example; static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH]; static volatile uint8_t ...
0
votes
3answers
1k views

How to use a coma as the decimal separator?

I have a LCD that displays a float variable. I would like to show a comma instead of a dot as the decimal separator. float temp = 23.50; lcd.setCursor(0, 0); lcd.print(temp); I want to show 23,50 ...
0
votes
1answer
81 views

Error declaring two-dimensional array: 'x' was not declared in this scope

I'm trying to declare a 2-D array where each letter in the alphabet is keyed to a corresponding LED in my LED strip. But when I try to declare the array, Arduino flags the values and gives me a "not ...
0
votes
1answer
228 views

Space needed for local String variable

I tried to run this code on my Arduino Uno clone (which has no function so far and is a shortend version of my programm): String rules [16][5] ={ {"B0 B5", "", "", "cs S0", "", }, [...] }; ...
1
vote
1answer
84 views

Interrupt volatile variable doesn't work as expected

Please examine the following code. volatile uint8_t myVar; void setup() { attachInterrupt(digitalPinToInterrupt(2), isr, FALLING); Serial.begin(115200); } void loop() { myVar = 0; while (...
0
votes
1answer
262 views

How do I properly convert a pointer (uint8_t* or void*) to a “normal” integer?

I'm writing a program for arduino that needs dynamic memory allocation frequently, but as I don't want the memory to get fragmented, I'm also writing a "memory handler" for it. This memory handler ...
0
votes
1answer
43 views

Variables displayed incorrectly

I am making a keypad and when I try to save the buttons that were pushed they reset back to zero. int tmp = 1; int digit = 1; int a = 0; int b = 0; int c = 0; int d = 0; int code = 0; void setup() { ...
1
vote
1answer
39 views

Allocation, initialization and scope

I realized I don't fully understand how Arduino code handles variable lifetime. My tendency is to keep variables in the narrowest scope (which I realize isn't as important in Arduino code, but, habits....
1
vote
4answers
980 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
171 views

Is this assignment valid or needs casting?

I have this assignment and while i don't get any error not even warning from the compiler. uint16_t Buffer[40000]; for (int n=0; n<40000 ; n++){ Buffer[n] = (0.99 * cos(((2.0*PI)/40000)*n); } ...
0
votes
2answers
140 views

Is it ok to declare variables inside timer interrupts?

I am building a real time audio application using the Arduino DUE. This application needs big arrays like: uint16_t sDelayBuffer0[46000]; The Due has only 96kb of RAM available so this array just ...
4
votes
3answers
818 views

Sizeof variables and Due's RAM

I set out to see how much space some arrays have. I used this test code bool state = false; uint16_t BuffA[46000]; uint16_t BuffB[20000]; uint16_t BuffC[20000]; uint16_t all = 0; void setup(){ ...
3
votes
2answers
2k 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 note sure about the "here is" function definitions and I ...
0
votes
1answer
209 views

Where to declare timer interrupt variables?

I have a situation where the majority of the code is residing inside timer interrupt functions. Setup() does what it has, loop() basically reads ADCs and then all the code is inside timer interrupts. ...
0
votes
2answers
44 views

How can I set a calculated value when my sketch is uploaded?

I have an Arduino based countdown timer that counts down the number of minutes remaining to an event and displays them on an LCD. Since the event's start time is fixed, I have to re-calculate my ...
0
votes
1answer
57 views

Current available SRAM? [duplicate]

I've reached the limit on available SRAM memory. I need to "cut down" some variables, but I actually don't know how far I need to go with it. Is there a way on measuring current available memory on ...
0
votes
1answer
50 views

How to keep a specific bit set all the time for bit masking I2C operations?

I've been working on I2C and I learned how to initialize, send and receive with I2C communication protocol. Next, I wanted to run the LCD1602 I2C adapter. But the module has a different bit masking, ...
2
votes
2answers
1k views

#define VS local static const char

Could someone give me a hint regarding what would be the best practice to save memory: should I #define strings or use local static const char arrays? Code example, option #1: #define ...
0
votes
2answers
39 views

Conditional compilation, how to determine whether a variable has been declared?

Whilst using #if/#end constructs, how can I determine whether a specific variable has already been declared?, e.g., #if [the variable "pinname" has been declared] Serial.print(F("Pin name: ")); ...
0
votes
1answer
1k views

Help with struct variable

I made a struct like this: typedef struct { int color[3]; int positions[4]; char init[20]; void (*fn)(); } buttons; and a variable like this: button test[1] = { {{0,0,0},{0,0,100,100},...
4
votes
6answers
6k 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
6answers
779 views

Store a variable?

I want to have a switch, that when on, will grab an analog number and essentially "freeze" it. Similarly to how STO> works on a TI83. What should I be using? Excuse my lack of technical terms, I'm not ...
0
votes
2answers
772 views

Checking for multiple values in IF separated by commata

My code is: if ((minute == 31) && (hour == 4, 6, 9, 11)) { digitalWrite(8, HIGH); } I want to turn on the LEDs when it is exactly 04:31, 06:31, 09:31, 11:31 However, the code above ...
0
votes
2answers
94 views

What is the opposite of this data operation?

If I store in an array a double-value in this format, in which format I should be able to read the same double out? double myDouble = 12.123456; byte myArray[] = {0x00, 0x00, 0x00, 0x00}; myArray[0] ...