Skip to main content

Questions tagged [code-optimization]

The process of improving the efficiency of a program such that is uses less memory and/or less computational time.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
248 views

Here's the code: https://pastebin.com/ypWe4NZw This is the output when I compile: Sketch uses 13086 bytes (42%) of program storage space. Maximum is 30720 bytes. Global variables use 1456 bytes (71%...
user6615434's user avatar
2 votes
0 answers
2k views

Hello Arduino enthusiasts! I've been working on a keypad lock system for school lately and I need some advice.Basically, my code checks if the entered passcode is the same than a predefined passcode ...
Arxkz's user avatar
  • 23
0 votes
3 answers
832 views

int value1; int value2; int runs1 = 0; int runs2 = 0; #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F, 16, 2); int inPin = 6; int val = 0; int push_count = 0; ...
idkfa's user avatar
  • 140
2 votes
3 answers
194 views

First-time poster here... I have the following code to randomize note values and store them in an array loop1[i], where i is a specific step in the loop: nextNote = random(-2, 3); note = note + ...
Erik's user avatar
  • 271
1 vote
1 answer
135 views

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 ...
Chandramauli Chakraborty's user avatar
7 votes
2 answers
588 views

When you have really small snippets of code that are repeated several times in your micro controller program, is it better to write a method? I mean better in terms of performance and storage usage. I ...
Lehue's user avatar
  • 193
2 votes
3 answers
2k views

Im using an Arduino Uno - All code at github.com/robbrad/AirQuality Current sketch usage: Sketch uses 23186 bytes (71%) of program storage space. Maximum is 32256 bytes. Global variables use 1428 ...
Rob's user avatar
  • 135
-1 votes
2 answers
4k views

I want to count the number of people in a room using a microcontroller (Arduino Uno). I have 2 ultrasonic sensors at a doorway about a 1.5m apart from each other. I want to increment the number when ...
smit's user avatar
  • 11
1 vote
2 answers
2k views

I'm taking a course on Arduino Uno programming and on today's talk I heard that the const data is optimized by Arduino, so that it occupies less space than the actual data type (namely, a const int ...
theSongbird's user avatar
1 vote
4 answers
255 views

Could I realistically be expecting some 25% - 50% code size reduction if I abandoned Arduino IDE's framework and moved to something more rudimentary such as AVR Studio ? I am using the EEPROM, Timer1 ...
kellogs's user avatar
  • 136
1 vote
3 answers
1k views

I am curious if the following scenario is possible. EICRB |= (0<<ISC60)|(0<<ISC61); EIMSK |= (1<<INT6); ISR(INT6_vect) { myISR(); } void myISR() { digitalWrite(led_off, ...
mgla's user avatar
  • 11
0 votes
2 answers
5k views

I am an amateur with Arduino and coding and I am learning in my lab class. My project consists of using a photoresistor to measure the brightness of a white LED. I have the following circuit built. I ...
O.L. Castle's user avatar
1 vote
1 answer
2k views

On Arduino forums, there's a post where someone improved the USB communication and made it super-fast. I don't understand how he did this, and I'm trying to recreate this, but failing. My test code I ...
The Quantum Physicist's user avatar
1 vote
1 answer
3k views

the following code will display the files on an SD card in an Arduino and allow the user to open a file of their choosing. Here's the code with a walkthrough of what it does. In the Init state, I ...
ATE-ENGE's user avatar
  • 941
1 vote
2 answers
535 views

Background: I have a uni assignment which requires an autonomous robot to do a number of tasks and then finish in a set spot after being triggered to start by an outside physical interaction. I've ...
James's user avatar
  • 113
12 votes
5 answers
4k views

Excuse me if it is a silly question, but I couldn't find an answer. I've been wondering for a while whether an Arduino (or generally any other micro-controller) gets happy if the code is light and ...
ahmadx87's user avatar
  • 549
2 votes
1 answer
1k views

I'm trying to receive remote information with an IR receiver and this is my code: #include <IRremote.h> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { ...
Ali Özgür's user avatar
-3 votes
1 answer
92 views

I'm a bit new to this and I have the following function that I'm having trouble getting it to compile. The intent is to create a message to write out to a software serial port. Inputs are two int ...
ATE-ENGE's user avatar
  • 941
1 vote
1 answer
89 views

Is it possible to use a name instead of a number to address an array? I was reading about enum lists and thought it might be possible. ie int array[3] = {something, somethingElse, somethingMore] ...
Matt's user avatar
  • 158
0 votes
1 answer
716 views

I am working on a project where I've mapped an IR remote control to certain functions. I am currently using a massive switch statement to control the program based on the IR remote button pressed. Is ...
Matt's user avatar
  • 158
2 votes
1 answer
351 views

Along all the "advanced" methods described in this article, does simple method as downscaling processor while delay makes a difference on power consumption? How much time does the clock alternation ...
madneon's user avatar
  • 225
1 vote
2 answers
1k views

I planed a 6x6 matrix with a Arduino Nano as controller. Its only possible to let one LED in the matrix lighten up. Any idea how I get the Code smaller? (Im a C Noobie ^^) ~Nico Circuit diagram: ...
Nico L.'s user avatar
  • 45
1 vote
2 answers
2k views

Could someone please demonstrate how to use a counter with the Arduino 'low power' library to wait for 10 minutes then digitalWrite 4000, HIGH and loop. (I don't mean the simple 'blink' sketch). I'm ...
Nikian's user avatar
  • 11
1 vote
4 answers
5k views

Arduino community. I have had experience with Arduino for 3 years now and have finally come to the conclusion to get rid of the delay function entirely. Below is the code to blink two LEDs a ...
Nathan Ramanathan's user avatar
0 votes
2 answers
961 views

I've followed the directions from this answer, to try and play music without delay. This is my code so far: #include "pitches.h" int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, ...
kok_nikol's user avatar
1 vote
1 answer
762 views

I'm currently working on a 10x10 LED Matrix which is controlled by 5 Shift registers using multiplexing. I've the problem that the Teensy 3.6 is too fast/slow. One part of my code is the Shiftout ...
Tom Stein's user avatar
  • 111
7 votes
4 answers
3k views

I want to store a few (8 as of now) IR codes into my Board's EEPROM. It would be great if someone could suggest a few tips to maximize the lifetime. The IR codes in my sketch are saved in array of ...
karx's user avatar
  • 235
0 votes
1 answer
2k views

I have a robot that uses two motors to skid steer. The robot gets input from three ultrasonic sensors (left, middle, and right) and a passive infrared sensor. If the robot detects a person in front of ...
Daniel Shields's user avatar
0 votes
1 answer
1k views

I am using a Pro Mini to read analog values and to send them via serial. Goal of the sketch is to stream these values to Serial as fast as possible, to obtain a steady stream of at least 1000 ...
FarO's user avatar
  • 339
1 vote
1 answer
141 views

I am currently using an Arduino Mega with a fast vibration sensor to trigger the components operation (force sensor, temperature sensor) and also toggle sleep mode. I am very new at this and I have ...
Worapat Sopa's user avatar
1 vote
3 answers
89 views

I'm getting a few errors when merging strings with constants. Here's the pertinent code... #define STATION_ID ABC123 #define STATION_PASS XYZ987 void loop(){ String path = "/weatherstation/...
Shpigford's user avatar
  • 484
2 votes
0 answers
579 views

I am reading a TSL1402R with an Arduino Mega2560. The code is based on the sketch from the arduino playground here:http://playground.arduino.cc/Main/TSL1402R The application is a digital caliper for ...
bigstew123's user avatar
3 votes
1 answer
135 views

I am currently reading a DS1307 adafruit breakout board and I need to drive two nixie tubes from a shift register. The shift register is running two 74141 IC chips. I have code that loops through all ...
Cheddar's user avatar
  • 133
2 votes
1 answer
599 views

I am using an ESP8266-12E with a PCF8547. I have managed to turn on and turn off LEDs using these two things. I am using these three commands to do it. Wire.begin(SDA_PIN,CLK_PIN); Wire....
KarmaCoding's user avatar
2 votes
1 answer
518 views

Sim800L's library can not compile on Arduino Due. Is there any way to create a library for Arduino Due? #include <Sim800l.h> #include <SoftwareSerial.h> Sim800l Sim800l; char* text; char*...
Ibn Sina's user avatar
0 votes
1 answer
2k views

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); ...
Rafael M.'s user avatar
  • 113
1 vote
1 answer
168 views

I have tried fading the RGB Led with different colour format and sequence. Working of Code :- When value of number is 1, the Red LED fades gradually and glow up with the delay interval of 10ms with ...
MICRO's user avatar
  • 500
2 votes
1 answer
1k views

I am using Dust Sensor GP2Y1010AU0F I downloaded the code from the manufacturer here: http://www.waveshare.com/wiki/Dust_Sensor /**********************************************************************...
Daniel Benedykt's user avatar
1 vote
1 answer
97 views

I'm working on a prototype which uses the RedBearLabs Blend Micro with the NSC's nrf8001 ble chip, but have ran into a problem that I'm not sure how to solve. I have two tactile buttons connected to ...
Vnu_Filip's user avatar
1 vote
1 answer
467 views

I'm using a Texas Instruments DRV2605 haptic controller in my project to drive a LRA vibration motor. I would like to calculate the LRA rated voltage during run time using the formula below as ...
JvwComputing's user avatar
0 votes
3 answers
29k views

For a school assignment I need to make a LED blink on/of 3 times then stop. Now I have come up with the following code: I think it's ''clean'' enough for what it has to do, but I have a feeling that ...
Jordakoes's user avatar
1 vote
3 answers
379 views

I am looking for a more elegant way to write a function that performs timer-based tasks as in the case of the code below, which essentially collects 5 sample values from a microphone module over a ...
gnzg's user avatar
  • 157
0 votes
1 answer
893 views

I want to use loop() iterations counter to execute some tasks periodically or tasks like debouncing. My other sketch is running every loop() at least 20 ms, and if i am using 5 ms time to wait to ...
user2882440's user avatar
3 votes
1 answer
2k views

It seems like the majority of Arduino applications are written without using classes / objects. Is there a reason for this? Does is slow down the Arduino or somehow present undesirable behavior?
Jacksonkr's user avatar
  • 327
5 votes
3 answers
4k views

I have been working on an arduino program, which has gotten rather large. I am close to hitting the 32k limit on Flash for my ATmega328p. I would like lower my program size by saving some of my many ...
riverrun's user avatar
6 votes
2 answers
572 views

I'm having some trouble conceptualizing how to go about implementing PID into my drone. There are a few ways I'm thinking about implementing the pipeline: Having one PID Object for each of the six ...
tuskiomi's user avatar
  • 205
2 votes
3 answers
6k views

I have some Arduino code that looks like: char packet = ser.read(); switch(packet){ case 'a': someobj.somefunc(); break; case 'b': otherobj.otherfunc(); ...
Cerin's user avatar
  • 1,698
0 votes
2 answers
113 views

I'm using an Arduino Mega and four of its interrupts. Each interrupt is only used to start/stop a timer, depending if it's rising or falling, so effectively runs the same function. Does anyone know if ...
Shaun Barney's user avatar
0 votes
4 answers
125 views

I'm a painful 128 bytes of my max for this Trinket. Any refactoring I could do to get down the size? #include <Adafruit_NeoPixel.h> #include <Wire.h> #include <RTClib.h> #define ...
Shpigford's user avatar
  • 484
2 votes
2 answers
439 views

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 ...
Shpigford's user avatar
  • 484