Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
The process of designing and writing source code as part of a program (or sketch) for Arduino. For questions about uploading code to an Arduino board, use the [uploading] tag instead.
30
votes
Accepted
How can I declare an array of variable size (Globally)
Your question has 2 parts actually.
1/ How can I declare the constant size of an array outside the array?
You can either use a macro
#define ARRAY_SIZE 10
...
int myArray[ARRAY_SIZE];
or use a co …
19
votes
Is using malloc() and free() a really bad idea on Arduino?
Typically, when writing Arduino sketches, you will avoid dynamic allocation (be it with malloc or new for C++ instances), people rather use global -or static- variables, or local (stack) variables.
U …
15
votes
Accepted
How much can I recurse? How much can I recurse? How much ca!@#QFSD@$RFW
If you really want to recurse (and as @jippie said it is a bad idea; subliminal message: don't do it) and want to know how much you can recurse, then you will have to perform some calculation and exp …
8
votes
for loop running infinitely
After a chat with OP, it turned out this was a more complex issue, probably a memory overrun.
This cannot be seen in this small snippet, but the whole program is using memory extensively (global vari …
5
votes
Accepted
Led on when not supposed to be
The behavior you describe is symptomatic of a floating input.
I guess you have directly wired your buttons between input pins and +5V (or GND, that won't change the observed behavior).
The problem i …
4
votes
Can I turn off a device using the 5V and analog pins?
Short answer: NO. It would fry your Arduino.
Long answer:
The current of Arduino pins is very limited (40mA max on UNO).
If you need to draw 1A, then you need a transistor between the Arduino pin a …
4
votes
Accepted
Use object of other class within class
In C++, a class that holds reference members (in your sample, LiquidCrystal& _Clcd1; and LiquidCrystal& _Clcd2;) must ensure these references are initialized at construction time, not later.
This mea …
4
votes
Accepted
portd not writing on digital ports 5 and 7
This is because on ATmega 32u4, which is used in Arduino Leonardo, pins 5 and 7 are not mapped to port D but to port C and E respectively, as you can see in the ATmega 32u4 - Arduino Pin Mapping.
…
3
votes
Why is int only 2 bytes?
One important fact about C and C++ languages is that their respective standards do not define the size (in bytes) of integral and floating point number types.
They just define minimal ranges and rela …
3
votes
Accepted
Allocate object memory statically; intialize it dynamically?
Using an initialize() method to a class is contrary to the principle of a class constructor, i.e. once a class instance has been constructed, it should be "ready to use".
As suggested by Ignacio's an …
3
votes
Accepted
4-digit 7 Segment LED displaying numbers in the wrong order
Here is a datasheet I found that seems a better macth for your display model (that's the datasheet for a display that I use):
http://www.play-zone.ch/en/fileuploader/download/download/?d=1&file=custo …
3
votes
Accepted
What are the benfits of global variables over static class members?
I can see no specific drawback in using static class members instead of global variables on Arduino. They will be managed the same in the end program.
The only difference I can see may arise based on …
3
votes
Why can't my .cpp file have a class of the same name?
#define XYZ
class XYZ { };
The first line tells the "C preprocessor" (called before C and C++ compilers) to replace XYZ with nothing everywhere it happens, hence after preprocessing, and before com …
2
votes
Accepted
Default value of global variables is not set
This variable is declared volatile which is generally meaning that it can be modified by an Interrupt Service Routine (ISR).
So it is perfectly possible that this ISR gets called before your setup() …
2
votes
Accepted
Timer1 stops firing
The problem you have is that you never reset Timer1 counter (TCNT1) when you stop a note and then play another one.
Also, changing the clock divider selection to "no clock" by clearing bits CS10 and …