Questions tagged [variables]
Variables are used to store data in a sketch/program.
162 questions
24
votes
4
answers
5k
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;
...
19
votes
5
answers
191k
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 ...
14
votes
5
answers
82k
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 ...
11
votes
1
answer
43k
views
int VS uint8_t VS uint16_t
This question is quite clear. What are the differences between an int, an uint8_t, and an uint16_t. I know it has to do with bytes and memory but can someone clarify me a bit?
Things I want to know:
...
10
votes
2
answers
5k
views
Is there a non-float alternative to pow()?
I've scoured the LANGUAGE REFERENCE in the Arduino web-site, and I can't find a non-Float equivalent to pow() I've got to be missing something big, but for the life of me, I'm stumped! I found pow() ...
9
votes
2
answers
4k
views
How to update a variable in an ISR using Timers
I'm trying to check the frequency of Timer3 using a counter. The value of the counter, declared as volatile, is incremented in the ISR and every second the sum is shown in the main loop and the value ...
7
votes
2
answers
3k
views
Can you use Serial Port as a variable?
I am doing a project where, for troubleshooting reasons, I find myself often swapping components to different serial ports. Maybe one time it's in Serial, then in Serial1, maybe I need to try if ...
6
votes
1
answer
3k
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 ...
5
votes
3
answers
1k
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(){
...
5
votes
3
answers
36k
views
Convert long to char array and back
I'm trying to store a state in my data logger. I can read/write fine to SD, but I can't wrap my head around reading/writing a long value correctly - I've build it down to converting it to char array ...
5
votes
6
answers
20k
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 ...
5
votes
1
answer
2k
views
Assuring an unsigned long int?
Basic question: How far do I have to go to assure that integer math is done correctly? For example, this is probably overdone:
unsigned long burnTime = 0UL;
unsigned long curBurnTime = 0UL;
// Do ...
4
votes
2
answers
1k
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 ...
4
votes
2
answers
103
views
Use large variables without using much memory
I've wired up a dot matrix, and I display characters on the screen by using something like the example code below.
The Char_B variable is a global variable in a library used by the Arduino, and ...
4
votes
2
answers
4k
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 ...