The process of improving the efficiency of a program such that is uses less memory and/or less computational time.
Questions tagged [code-optimization]
130 questions
4
votes
2 answers
Problem with inaccurate delays between sensor readings
During the last two months I have been working on a project that consists of using a Seeeduino Stalker V2.3, two AM2305 sensors, a TSL2561 sensor, an HC-05 XBee module, a 1,800 mAh 3.7V LiPo, a 7 cm x 7 cm 5V solar cell, and a waterproof suction…
OpenAGRO
- 41
- 2
3
votes
1 answer
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 each motor in the loop instead of using the…
Steve
- 33
- 3
2
votes
2 answers
Possible to condense this if statement?
I have this if statement:
if (now.hour() == 5 && now.minute() == 10 && now.second() == 0 && now.dayOfTheWeek() != 1 && now.dayOfTheWeek() != 7){
Is there a way to condense that for the purposes of saving on some bytes?
Ultimately trying to say "At…
Shpigford
- 484
- 2
- 8
- 23
1
vote
0 answers
How do I optimize this IRremote code?
I am using a ATTINY85 Digispark board with an IR receiver to light some LEDs in my project. The Digispark has a limitation that does not allow it to use the IRremote.h library. I know that there a series of workarounds for that (including a…
user3347814
- 123
- 5
1
vote
0 answers
Can a Windows 10 computer use Arduino IDE 1.8.10 sometimes AND use Arduino IDE 2.0.0 the rest of the time?
Can Windows 10 computer use Arduino IDE 1.8.10 sometimes, AND use Arduino IDE 2.0.0 the rest of the time?
martymarty
- 111
- 1
- 3
1
vote
3 answers
Is there a more elegant way to check highest / lowest sample data?
N00b question,
Is there a better way for readability / elegance / DRY etc to check various sensor values for high/low record value? This code works, but looks like the long way round.
void checkRecord() {
if ( temp.current > temp.high) {
…
opt10n
- 11
- 1
1
vote
1 answer
LED Programme where it delays the amount written in the Serial Monitor
I have written a simple code to delay the blinking of LED 13, the delay time is set by us.I have incurred a problem when I enter a 2 digit value in the serial monitor.There is some problem with the ASCII. Is there a way to solve this problem without…
Chandramauli Chakraborty
- 117
- 6
1
vote
1 answer
How to int variables with similar names without tons of code?
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 = 9;
int led9 = 10;
int led10 = 11;
int led11 =…
智障的人
- 113
- 5
0
votes
1 answer
How to shorten this code (because my sensor reads slowly)?
I'm making a fare meter for our school project. I have too much lcd.print code. This code is not finished yet. My only concern is how to minimize the usage of lcd.print. I think it's the one that makes my sensor reading slow.
I'm new at Arduino;…
SkilleX
- 11
- 2
0
votes
2 answers
Merging of two functions
This is my Arduino code that checks the water Level of two different water reservoirs via 2 water Level Sensors A and B:
#define Water_Level_A 5;
#define Water_Level_B 6;
boolean Water_Level_Check_A(){
boolean Result =…
Peter S
- 125
- 5
0
votes
1 answer
Is it possible to pass HIGH and LOW values as parameter in a function?
I've created the following function:
void runMotor(int _dir, int _step, int wait){
digitalWrite(_dir, HIGH);
for (int x = 0; x < 3200; x++) {
digitalWrite(_step, HIGH);
delayMicroseconds(wait);
digitalWrite(_step, LOW);
…
Ramuyko
- 113
- 1
- 4
0
votes
4 answers
Refactor to save bytes?
I'm a painful 128 bytes of my max for this Trinket. Any refactoring I could do to get down the size?
#include
#include
#include
#define LEDPIN 1
#define TONE 4
#define BTNPIN 3
RTC_DS1307…
Shpigford
- 484
- 2
- 8
- 23
0
votes
1 answer
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); a++){
pinMode(allOutputPins[a], OUTPUT);
…
Michael Rader
- 326
- 2
- 5
- 17
0
votes
3 answers
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++;
}
VS
char c = Serial.read();
if (c != '\r' && c !=…
Martynas
- 538
- 3
- 10
0
votes
1 answer
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;
long turn6;
long turn7;
long turn8;
long turn9;
long…
智障的人
- 113
- 5