Questions tagged [variables]

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

Filter by
Sorted by
Tagged with
-2 votes
1 answer
27 views

how to save float with 3 decimal places [duplicate]

i am transmitting sensor data from my atmega328p to my esp8266. The Sensordata has 3 decimal places. The esp8266 sends this data to my pc and there I see only two digits. This is because the data is ...
user avatar
  • 1
0 votes
1 answer
62 views

Inconsistent behavior of include statements?

This question deals with fonts. Well, actually, singular include files with constants that form bitmap fonts or images for LCD or OLED displays, such as this one: https://github.com/ThingPulse/esp8266-...
user avatar
0 votes
3 answers
61 views

How do I modify the value of a variable when I press a switch

I am new to arduino and I want to make a project where I have a motor spinning clockwise then when a button is pressed it spins anti-clockwise and if it is pressed again it goes back to clockwise etc.....
user avatar
1 vote
1 answer
103 views

1 global variable consuming 19% of memory

I am working on a simple project on talking to the serial monitor, and my only global variable ("int" type, named "incomingByte") is consuming a lot of memory. There is no problem ...
user avatar
-1 votes
1 answer
29 views

Initializing an object as class member resulting in linking error?

I'm a little dumbfounded as to why this isn't working. I keep getting the following linker error: In file included from src\ac.cpp:1:0: src/ac.h:9:21: error: expected identifier before numeric ...
user avatar
  • 3
2 votes
1 answer
168 views

Space taken by Global Variables

Using Nano's for small programmes I get compilation reports about the amount of space taken by global variables. On a typical progamme it says something like Sketch uses 16316 bytes (53%) of program ...
user avatar
1 vote
2 answers
288 views

Can bool variable be NULL

I want to know if bool variable can be null, or it must have to be true or false: Base on Arduino description: A bool holds one of two values, true or false. (Each bool variable occupies one byte of ...
user avatar
  • 151
2 votes
1 answer
63 views

Global Variable not updating…

I'm building a small project to maintain a copper plating tank's temperature and filter pump duty cycle. I'm using the Adafruit Feather platform to hold an 8 segment matrix coupled with a Teensy 3.2 (...
user avatar
2 votes
2 answers
945 views

How to write nonblocking code, for polling sensor at 100 Hz

I'm using this piece of code to try to poll an IMU sensor at 100 Hz (for a AHRS sensor fusion library). void loop(void) { // nonblocking code variables static uint32_t last_ms; uint32_t ms; // ...
user avatar
-1 votes
1 answer
56 views

How to deal with global variables in a program which has more than 5 functions and every function accesses them without any problem? [duplicate]

I know that using Global Variables in programming may create lots of problems in long term , like , Bugs , Lags and more . I am working on a program which has more than 5 functions which need to ...
user avatar
1 vote
1 answer
293 views

nRF52 non-volatile storage/recall of a variable - is there a simple solution?

I have an Arduino program written for the nRF52 with which runs for a pre-set time-value (i.e. 2 minutes) before shuts off automatically. The variable time-value can be changed via BLE-write by the ...
user avatar
  • 69
1 vote
0 answers
71 views

Why does this piece of code overflow at 255?

Im having a problem where i got unsinged long variable and i need to increment it in eeprom everytime setup starts and it overflows at 255 back to 0. unsigned long NumberOfBoots = 0UL; #define ...
user avatar
  • 11
0 votes
1 answer
104 views

does EEPROM reset itself when a new code is uploaded?

I have a Nodemcu with which i'm doing a project. So whenever there is a power loss i want values of some of the variables to not be reset, because of that im trying to store the values in EEPROM of ...
user avatar
1 vote
2 answers
172 views

How to reset a variable just before entering a function? [closed]

I am facing a problem where the if condition in the function waterNowrun is able to execute once after the program starts as the variable v is 0 at the start, but upon starting it again the if does ...
user avatar
  • 452
0 votes
1 answer
39 views

How to make ultrasonic and light sensors detect whether a person moving in or out

I am trying to make a circuit that will be used for turning on a light whenever there are 1 or more people in a room. I need to add to a variable counter when someone enters and subtract when someone ...
user avatar
0 votes
2 answers
112 views

why can Arduino variables of int type contain a value such as A2

How come the following statement is true: int inputPin = A2; I thought int variables can only hold integer numbers. Is the A just a representation of a number? Thanks for any help
user avatar
0 votes
1 answer
42 views

non asssign variable using by for in loop() can remeber last value. what happen here?

I modify this code from my friend and it look strange. void setup() { Serial.begin(115200); Serial.println("reset"); } void loop() { for (int d; d <= 32767; d++) { ...
user avatar
  • 131
1 vote
1 answer
191 views

using a variable to index an array

I'm using the keypad library to return a number 1-9. (im fairly sure this returns an int) I have an array (data) showing the state of each button press. so i would like the number returned by the ...
user avatar
  • 51
1 vote
1 answer
203 views

Printing vairable with U8GLib

I have this code that takes temperature and humidity values from a DHT11 sensor and number of faces from an external python code and prints them on an OLED screen but instead of values of variables it ...
user avatar
  • 19
1 vote
0 answers
461 views

Nextion won't update text using data passed in Arduino Uno serial print

Q: Is it possible to send data in variables from Arduino to Nextion through SerialPrint? If so, what is the correct syntax? I have an Arduino Uno connected to a Nextion NX4024T032 and a Sunfounder ...
user avatar
0 votes
1 answer
133 views

Change/declare a constant in setup and use it in loop

I want to change or declare a constant in the setup() and then, I want to access it in the loop(). I have searched a lot, but the only questions I found could be solved by declaring the constant in ...
user avatar
  • 11
1 vote
3 answers
134 views

variable name standards, e.g best method to send motion_detect=true

I am working with some sensors and sending data to a public web server via http, I was thinking this server can be possibly used by more people to send their data and server displays a chart. I was ...
user avatar
  • 242
1 vote
1 answer
146 views

I want to create 10 levels with one button but this code shows only level 1?

#include <Adafruit_NeoPixel.h> const int PIN = 4; const int NUMPIXELS = 10; const int BUTTONPIN = 6; int buttonState = 0; int PINState = 0; int level = 1; int dt = 100; Adafruit_NeoPixel pixels(...
user avatar
7 votes
2 answers
2k 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 ...
user avatar
  • 181
1 vote
1 answer
255 views

How do i improve this Code? (or how to pass a Char String into a Function to behave like a Variable)

Sorry i am a beginner and amateur when it comes to coding, can somebody help me to make the code inside the loop() less "monkey-like" by using a proper function? I have tried a lot and at ...
user avatar
  • 11
1 vote
0 answers
50 views

Having a bunch of global variables or calculate them on the go on an Arduino, as far as memory is concerned

So I'm new in the arduino world but I have a grasp of object oriented programming, and decided to write a little library for running games on an arduino mega using a display. My question is, I'm ...
user avatar
  • 11
0 votes
2 answers
147 views

Convert character to Integer while leaving encoded

I have two characters, that I get by Bluetooth. char a = SerialBT.read(); char b = SerialBT.read(); According to the Arduino Reference, decoded data stored in a char gets encoded to ASCII text. I ...
user avatar
1 vote
1 answer
272 views

Global variable changes its value when loop starts again

I have a problem with the global variable calibrationValue. It is initially set with the correct value and is also displayed correctly in the output. As soon as the loop function is restarted, the ...
user avatar
  • 13
0 votes
1 answer
93 views

Storing IR Sensor value not working

This is my first time working on Arduino for my project and I ran into an issue. I'm trying to make a very simple Vending Machine. Coin or any obstacle passes in front of the IR sensor and based on ...
user avatar
0 votes
1 answer
139 views

What does display.setSegments(&segto, 1, 1); do?

I am using a TM1637 display for my Arduino Uno. The goal was to just light up one point of the colon in the middle - what seems to be kind of impossible to accomplish. During research I stumbled over ...
user avatar
0 votes
1 answer
3k views

Getting enum name from enum instance [closed]

Hello Arduino Stack Exchange, I have an an enum instance called state: enum States { SLEEP, AWAKE, CRAZY } state; States state = SLEEP; I would like to convert the value of state to a String so ...
user avatar
1 vote
1 answer
448 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 ...
user avatar
  • 13
0 votes
1 answer
237 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 ...
user avatar
  • 107
2 votes
2 answers
472 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 ...
user avatar
  • 31
0 votes
1 answer
175 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 ...
user avatar
  • 315
1 vote
1 answer
97 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 ...
user avatar
0 votes
1 answer
110 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()+' ...
user avatar
  • 242
1 vote
4 answers
708 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(...
user avatar
1 vote
2 answers
32 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 - ...
user avatar
1 vote
2 answers
4k 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 ...
user avatar
0 votes
1 answer
50 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 ...
user avatar
0 votes
0 answers
35 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(...
user avatar
  • 790
0 votes
1 answer
1k 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 ...
user avatar
0 votes
1 answer
1k 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, ...
user avatar
0 votes
3 answers
2k 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 ...
user avatar
  • 1
2 votes
3 answers
746 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 <...
user avatar
-1 votes
1 answer
230 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 ...
user avatar
0 votes
2 answers
348 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 ...
user avatar
  • 225
0 votes
1 answer
50 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 ...
user avatar
0 votes
2 answers
165 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 ...
user avatar
  • 3