Questions tagged [coding-standards]

19 questions
32
votes
4 answers

Is it better to use #define or const int for constants?

Arduino is an odd hybrid, where some C++ functionality is used in the embedded world—traditionally a C environment. Indeed, a lot of Arduino code is very C like though. C has traditionally used #defines for constants. There are a number of reasons…
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
29
votes
8 answers

Are global variables evil in Arduino?

I'm relatively new at programming and many of the coding best practices I'm reading effectively state that there are very few good reasons to use a global variable (or that the best code has no globals at all). I've done my best to keep this in…
ATE-ENGE
  • 941
  • 3
  • 19
  • 32
12
votes
1 answer

Which C++ standard does the Arduino language support?

The "Arduino language" (as they call it) of the Arduino IDE 1 is obviously C++. Which C++ exactly? I tried to figure it out myself (Arduino IDE 1.8.13 for Arduino Uno), but I can't conclude what C++ standard it supports. From these tests, it seems…
Thomas Weller
  • 1,058
  • 1
  • 8
  • 22
2
votes
1 answer

Doubt in coding part in blink without delay

Code 1 (here unsigned long currentmillis = millis() is in loop area): const int LED = 2; unsigned long previousmillis = 0 ; const long delaytime = 1500; int ledstate = HIGH; void setup() { pinMode(LED,OUTPUT); } void loop() { unsigned long…
2
votes
3 answers

Code with if multible conditions

My project has 4 float switches, 2 valves and 3 pumps. I created a sketch and uploaded it. But my project keep all "OUTPUT" at "HIGH" all the time. I couldn't find what the problem, can you help? This is my sketch: #include #include…
user56886
  • 23
  • 2
2
votes
0 answers

Encoding clock signal into linear block codes

In the VirtualWire library, it is possible to encode the clock signal as the library is doing with 4b/6b coding. This is possible because VirtualWire uses convolutinal coding, where the information is spread along the sequence. But, is the same…
2
votes
2 answers

Is RX1 and TX0 the same thing as TX and RX? Will there be a difference in the way I program it?

I have an Arduino. I'm not sure if RX1 and TX0 the same thing as TX and RX? Will there be a difference in the way I program it? For example, do I treat RX1 and TX0 as RX and TX in the Arduino IDE when coding? This is the chip I have. On the chip it…
JoeB
  • 51
  • 2
  • 5
1
vote
0 answers

Why does the LED state behave differently?

I wanted the sensor to be high when I press the button, but when DigitalRead does low, the LED turns on, when it does high, the LED goes off. Whereas when the digitalRead is high, isn't it supposed to turn on the led? int pirPin = 8; int ledPin =…
Sabri73
  • 51
  • 8
1
vote
3 answers

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 wondering if there is a IOT industry standard when…
adrianTNT
  • 252
  • 4
  • 17
1
vote
1 answer

Are there any standard ways of reporting a runtime error?

I'm new to Arduino but I'm an experienced programmer. I'm wondering if there are any common functions for reporting errors in Arduino programs? For example, in JavaScript we have the alert() function, or on Unix you can write a message to standard…
1
vote
5 answers

Do Arduinos meet military standards?

Do Arduinos meet military standards? If not, where does it fall short? Is it something internal to the chip which might be corrected via external circuit? How could I evaluate the potential of a device I'm building?
sean
  • 131
  • 1
  • 4
0
votes
1 answer

coding standards for bigger projects

I'm starting a decently sized project around arduino/ATMELavr, and I came to wonder if there are any commonly accepted C/C++ coding standards or style guidelines specifically aimed at embedded C++/arduino. I've worked mostly with python recently,…
Laurent S
  • 103
  • 2
0
votes
1 answer

Do You Put a Break after the Last case in a Switch?

The Arduino Switch Case Reference has a switch structure written two different ways: First in the Syntax as: switch (var) { case label1: // statements break; case label2: // statements break; default: // statements } and…
ATE-ENGE
  • 941
  • 3
  • 19
  • 32
0
votes
2 answers

GPS and Arduino

I am working on a project with an Arduino Uno. I want to know if the latitudes and longitudes can be input to the Arduino for the Arduino to move to that particular location. If it's possible then which sensors or actuators are to be used? Please…
0
votes
2 answers

While doesn't the loop terminate?

I have a have project of Up Down counter using Arduino with seven segments, in which when I continuously press the push button, the counter moves upward from 0 to 99. When I release the push button, the counter moves downwards from the previous…
1
2