The process of improving the efficiency of a program such that is uses less memory and/or less computational time.
0
votes
1answer
15 views
Using for loop to set pinMode
I notice problems with my output pins when I use this method of setting their pinMode:
int allOutputPins[] = {3, 4, 9, 10, 5, A3, 11, 12, 7, 8, A1, A2};
for(int a = 0; a < sizeof(allOutputPins); ...
0
votes
3answers
27 views
How to store IR data needed for AC controll in less space?
I'm trying to controll an AC unit but the issue is space - right now, I store the data like this:
consts PROGMEM unsigned int Signal_Heat_Fan0_Temp30[] = ...
1
vote
3answers
88 views
Are static variables in a function bad?
For my code I use a couple of static variables.
But when I search the internet, they seem "evil".
For example: I have a function which will be executed every loop (5ms looptime).
to increase the ...
0
votes
1answer
30 views
SD Library writing char in a file
I'm trying to write into a file using this code from the example of the library:
String dataString = "";
int sensor = 0;
dataString += String(sensor);
dataString += ",";
sensor +=1;
File dataFile = ...
0
votes
3answers
37 views
Simple question about && vs ||
I want to skip all '\r' and '\n' chars and I have IF statment:
char c = Serial.read();
if (c != '\r' || c != '\n') { // <- This line interesting
mAnswer[mAnswerLength] = c;
mAnswerLength++;
...
1
vote
2answers
255 views
How to read code from Arduino Uno to Arduino IDE? [duplicate]
we can upload a code into Arduino UNO from our computers, but how about reading code? Can we read and get C codes from compiled codes from Arduino hardwares? My second question is that will we read ...
0
votes
2answers
63 views
Light sensor acting up when used with other code
I have a light sensor that works fine and outputs the correct data to the serial monitor when I only upload the following code to the nano:
const int lightSensorPin = A0;
int lightSensorValue = 0;
...
1
vote
1answer
27 views
How to int variables with similar names without tons of code? [duplicate]
I'm using int with 14 LEDs to specify pins, but I don't want to use int 14 times, like this:
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 ...
2
votes
1answer
56 views
Cleaning up code? Removing repetition?
I am using Adafruit motor shield, I am running multiple DC motors for different amounts of time, but to start at the same time - I have researched that to do this I have to monitor the elapsed time of ...
0
votes
1answer
69 views
Shortening large chunks of code
Some of the code that I have is unbearably long and drives me insane. I don't know if there were simpler ways to doing what I am doing.
long turn1;
long turn2;
long turn3;
long turn4;
long turn5;
...
4
votes
1answer
75 views
Overview of compiled code size
When I compile my code, the Arduino IDE returns the binary sketch size in byte.
Is there a good way to find out (approximately) what function or what part of my code takes up how much memory in ...
0
votes
2answers
132 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
1answer
91 views
Control arduino with keybaord via computer
I'm brand new to arduino but I'm trying to figure out how to set up a WASD steering system for my robot I made.
I have the physical setup all ready but I don't know the code to use that would allow ...
0
votes
1answer
56 views
Sweep with two shift registers
I am working with 8 dual color LED's and 2 shift registers. My connections are in place. But I do not understand how to work with 2 shift registers.
So I am trying to make this: turn the first led ...
0
votes
2answers
108 views
releasing memory in sub-function
I'm doing a program who get a line from the SD and shows it, this function is called getData()
FULL CODE:
#include <SD.h>
#include <MemoryFree.h>
File myFile;
int stringIndex = 0;
int ...
1
vote
1answer
150 views
How to enable maximum Dead Code Removal?
I am running out of code and data memory space on ATMega328P.
Code size is big as I used several libraries, but, I only use a few functions of those library.
Apparently, the default IDE is only ...
0
votes
2answers
127 views
What is the simplest way to “ask” the arduino which input pins are HIGH?
I am trying to build a 36-line cable tester, using the Digistump DigiX (99 i/o pins). Digital pins 0-35 are outputs, connected via the cable in question, to (in a perfect world) digital input pins ...
5
votes
2answers
11k 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 ...
1
vote
2answers
80 views
Questions on programming logic?
So I am learning arduino code by going through examples and playing with them, and I came across something interesting. I am not fluent in any coding language but I am fully familiarized with computer ...
4
votes
4answers
849 views
What's the most efficient implementation of map(x,0,1023,50,250)?
I recently noticed how the map() function in Arduino was bulky in both terms of flash space used and time taken to execute, largely because it deals with long and involves a division and ...