Variables are used to store data in a sketch/program.
1
vote
2answers
26 views
Why declare analog pins as ints?
I often see code like this:
const int piezo = A0;
const int sensorPin = A1;
From my understanding, an int variable can hold things like -123, 0, 1, 456, etc.
How can A0 or A1 be an int?
0
votes
2answers
35 views
IDE avoiding math operation
I have no idea why this has been happening:
byte potenciometro = 0;int redpin=9;
void setup() {
Serial.begin(9600);
}
void loop() {
int valor=analogRead(potenciometro); delay(50);
Serial.println(...
8
votes
2answers
724 views
Is there a non-float alternative to pow()?
I've scoured the LANGUAGE REFERENCE in the Arduino web-site (https://www.arduino.cc/en/Reference/HomePage), and I can't find a non-Float equivalent to pow() I've got to be missing something big, but ...
1
vote
1answer
61 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:
...
0
votes
3answers
54 views
use button to select variable
i have a need to use 3 buttons a a simple option/variable selector at sketch start up ...
Pretty much at startup , script must wait for button press ( one of 3 ) , when button is pressed , use that ...
3
votes
2answers
54 views
Format hour and minute integers to HH:MM format (char*)
In Arduino code, I'm calling the getTextBounds() and print() API methods on my TFT handler object which accepts char* parameters and I have two integers holding a specific time's hour and minute part, ...
3
votes
2answers
65 views
Update variable using buttons
I made a part of code to change the temperature limit for alarm system. On warm days user have to change the temperature limit with buttons and OLED display.
The question is: How can the variable ...
1
vote
1answer
61 views
Help avoiding floating point math
I'm using a Texas Instruments DRV2605 haptic controller in my project to drive a LRA vibration motor. I would like to calculate the LRA rated voltage during run time using the formula below as ...
0
votes
2answers
43 views
How can I move these global variables to be
I'm taking a sample I found on the web about how to get ROS and arduino to communicated together over serial. I have the sample working and now I'm moving the idea of the sample into my OOP project ...
1
vote
1answer
52 views
Avoid global variables with classes
I want to avoid global variables when using my own classes in Arduino. Here is a example.
void setup(){
/* setup here */
classA objectA;
}
void loop(){
objectA.someMethod();
}
I know that my ...
0
votes
1answer
67 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, ...
2
votes
3answers
257 views
Manually Declare Global Variable
Is it possible to manually declare a global variable that is inside of a function. The only current way I know how to do so is to declare that variable within the setup() function or simply outside of ...
0
votes
0answers
30 views
Button used to add or substract from “x”
I'm using an Arduino UNO and im trying to make with 2 push buttons 3 diffrent speeds for a motor. I started with the base code for the buttons and then im gonna add the motor but i kinda got in a bit ...
0
votes
1answer
13 views
Large values are changed by Arduino when viewing with `Serial.print()`
Why are (big) values being changed?
I tried out printing some values and noticed bigger values are changed more, they seem to be rounded to quarters and then to halves when the value gets bigger.
...
0
votes
2answers
69 views
Why can't I declare variables inside an if statement?
I have a void function that helps me set the time on my arduino clock. I need to use the same function twice - once for the alarm and once for the actual time. The variables I am defining need to ...
0
votes
1answer
96 views
Arduino Memory Best Practice
So I have been diving deep into AVR programming and have seen several different ways of defining constants. I know that some of these methods are from "C" and others are from more modern "C++" methods....
1
vote
0answers
25 views
incoming GSM data stored as variable in code
I am using an Arduino Mega board with a SIM900 GSM.
My goal is to be able to text the GSM with a value of two digits (ex: 79) and then store that value as a variable in the code.
I know how to set ...
1
vote
0answers
67 views
How to get Type name of a variable on Arduino
I found this post and implemented the code in a separate classed and then passed different variables to it in an attempt to get the type name printed to serial.
The code compiled and worked fine but ...
0
votes
1answer
52 views
Arduino join multiple strings and numbers and then seperate them
OK, I'm working on a remote controlled robot. Both the robot and the remote use Arduino with a Bluetooth shield. The Bluetooth is working and I need to send something similar to this over Bluetooth:
...
1
vote
2answers
183 views
How do I correctly use enum within a class?
I am trying to set the status of an object from a private enum and I'm not sure how to get the private member to the public version in the constructor, and I'm pretty sure I should not be using byte ...
1
vote
2answers
64 views
Append Text to Variable Names: Please Help Me Shorten This Code
I'm trying to shorten the code under "setup" below, where I have over 120 variables that are being read from an external EEPROM. There is a pattern where the variable that stores the position of the ...
0
votes
1answer
279 views
How to change Multiple variable values through Serial Monitor
I am trying ... with minimal success to change/Check and also run voids through the serial monitor .the code i put i am having probles is that when i am try to send a value larger than 9 the value ...
5
votes
2answers
60 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 ...
0
votes
0answers
33 views
Variable Confusion [duplicate]
I'm very confused about how variables work in C++.
In this program...
boolean debounce(void)
{
static boolean buttonState=LOW;
static boolean lastButtonState;
boolean currentState = ...
2
votes
1answer
130 views
Run code via NRF24L01+ command “dynamically”?
I'm trying to make a home automation setup but I'm having a bit of trouble.
I want to be able to send commands of varying sizes to my arduino, separated by "|" and after receiving it completely it ...
17
votes
3answers
2k 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;
...
1
vote
1answer
103 views
Why is my variable not getting updated?
I have the following snippet of code:
const unsigned long fiveMinutes = 5 * 60 * 1000UL;
unsigned long lastCheck = 0 - fiveMinutes;
unsigned long now = 0;
void loop() {
now = millis();
if ( now -...
1
vote
1answer
748 views
Converting float to String
How can I convert a float value into a String object without implementing any library?
I'd like to avoid using char array.
1
vote
2answers
291 views
How to count the number of times a changing variable reaches a peak value
I am recording a varying distance with an Ultrasonic sensor and Arduino but my problem is I want to display the number of times this variable reaches peak (at an instance the value will be increasing ...
0
votes
2answers
499 views
How to add data without pre-defining variables?
I am currently working on a RFID card reader. I need the reader to send the ID to a storage space.
What I am trying to achieve is a person swipes their card, enters their name on the serial monitor, ...
0
votes
2answers
3k views
Arduino raise the error: `does not name a type` when an Object is used outside of the main two blocks setup and loop
I have this:
class Person{
public:
int age;
};
Person p;
p.age;
void setup() { ... }
void loop() { ... }
And I got this error:
Compiling 'MyProgram' for 'Arduino Mega w/ ATmega2560 (Mega ...
0
votes
1answer
359 views
Global Variable not able to be accessed in function?
I am trying to compile an Arduino program that takes analog input. However, when I declare multiple global variables, it often will not compile and because it throws an error that the variables aren't ...
2
votes
3answers
379 views
How do I turn on or off an array of LEDs based on the value of a variable?
I've created a function whereby an int ('cleanCount') automatically goes up or down (0-1000) based on the situation. The value changes every few milliseconds.
Based on the value, I would like to ...
1
vote
1answer
626 views
How to accept user input (array, variables,…)
I am working on a project using my Arduino mega2560 that triggers a solenoid (maximum of three solenoids), my camera and my flash (maximum of two flashes). The core routine is there, and working.
...
0
votes
1answer
339 views
Arduino UNO + CC3000 Wifi Shield, Reading webpage data
I'm new so I might be making a stupid mistake, but I'm declaring:
char dollars;
at the begging of file, afterwards I'm reading a data from a web page, printing it to my serial. That part work well. ...
0
votes
2answers
494 views
Program button to switch between two values
There is a function on one of my programs I want to be switch on and off by pressing a button. The button is unbiased otherwise I would set the function to read the button's status of HIGH or LOW.
So ...
0
votes
2answers
1k views
Matlab to Arduino communication
I am doing some computations on Matlab and I need to send those values to an Arduino Leonardo through USB serial connection. I need to send 2 variables which can vary from -400 to +400. I'm saying ...
0
votes
1answer
133 views
Can't store temperature in variable ( for further processing)
I am trying to store temperature data in a variable, so that I can use it for making a JSON object, but the problem is, that when I try to store the temperature in a variable, it prints out the wrong ...
6
votes
1answer
1k 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 ...
2
votes
1answer
462 views
How to pass value of a function from the RFID-RC522 library into a variable then be sent into either serial or ethernet?
I'm using an RC522 RFID reader with an Arduino UNO. There is a function?? (or whatever it's called :)) in Miguel Balboa's new MFRC522.h library which is mfrc522.uid.uidByte[i] that prints the bytes of ...
6
votes
2answers
907 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 ...
3
votes
3answers
7k 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 ...
4
votes
1answer
816 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 ...
0
votes
3answers
619 views
Help with a function that accepts different parameter types
I'm trying to create a function that prints out an XML tag with a value. I have the code below, but kind of stuck. I'd like to be able to call the function, and pass a value that could be a float, int,...
5
votes
2answers
36k 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 ...
0
votes
2answers
144 views
Debugger with Breakpoint and Variable read/set capability
Is there any free/open or commercial/paid Arduino IDE Sketch Debugger (not Atmel chip factory standard tool set) with Breakpoint and Variable read/set capability?
I read about VM on web. Is there ...
0
votes
1answer
520 views
How to send multi variable information over serial?
I would like to send information between my Arduino and my computer. Is there a way to send multiple variables from one Arduino? If so, how would I go about separating the variables?
5
votes
1answer
5k 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 ...
1
vote
1answer
970 views
Trouble with variable types and integrating DHT11 temperature sensor
I am trying to modify this sketch;
https://github.com/itsallvoodoo/home_automation/blob/master/Arduino_HVAC_Controller/HVAC_Controller/HVAC_Controller.ino
But I have a different temperature sensor, a ...
0
votes
1answer
138 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 ...