Variables are used to store data in a sketch/program.
4
votes
5answers
186 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
4answers
58 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
44 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
52 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] ...
0
votes
3answers
31 views
decomposition long number to byte and recomposition With FRAM
I'm using Adafruit FRAM for my little project and have some trouble with recomposition of LONG Variable , right now the recomposition on INTEGER it's fine.
Where I'm wrong with recomposition of LONG ...
1
vote
2answers
77 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
vote
0answers
34 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
3answers
52 views
How to explain the need/advantage for volatile in terms of microcontroller instruction flow
I know there are already many questions why volatile is used when it comes to interrupts.
But explanations like this doesn't help to picture what really happens:
Specifically, it directs the ...
1
vote
2answers
102 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 <...
2
votes
3answers
183 views
Confusion in the use of byte variable
A byte stores an 8-bit unsigned number, from 0 to 255.
I can understand the following line:
byte b = B10010; // "B" is the binary formatter (B10010 = 18 decimal)
But I also saw a use such as:
...
1
vote
2answers
37 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
39 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
755 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() ...
1
vote
1answer
233 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
76 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
99 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
162 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
66 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
62 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
153 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
127 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
535 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
1answer
14 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
112 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 ...
1
vote
1answer
131 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
30 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
97 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
55 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
246 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
69 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
334 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 ...
2
votes
1answer
144 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 ...
18
votes
5answers
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
142 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
1k 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
338 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
649 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
4k 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
403 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
461 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
704 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
359 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
563 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
149 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
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 ...
2
votes
1answer
545 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
1k 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
8k 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 ...