User Tools

Site Tools


arduino_code_efficiency

If you want to send us your comments, please do so. Thanks
More on comments


Code efficiency

Declaring strings

It does not matter for the size of the code is const is put in front of

  • char variable[ ]= “Text”;
  • String variable = “Text”;

or not

Boolean Constants

true and false
HIGH and LOW

bool test = false;
pinmode (7, INPUT_PULLUP); // Define pen 7 as an input with a pullup so when not connected it is a HIGH
 
if ( test ) { // is the same as
if ( test == 1 ) { // is the same as 
if ( test == true) { // This is the preferred syntax
 
if ( digitalRead(7) ) { // is the same as
if ( digitalRead(7) == 1 ) { // is the same as
if ( digitalRead(7) == HIGH ) { // This is the preferred syntax
 
 
if ( !test ) { // is the same as
if ( test == 0 ) { // is the same as 
if ( test == false) { // This is the preferred syntax
 
if ( !digitalRead(7) ) { // is the same as
if ( digitalRead(7) == 0 ) { // is the same as
if ( digitalRead(7) == LOW ) { // This is the preferred syntax

Toggle

  test = !test // Test becomes the opposite of itself. From true to false or from flase to true.
               // This is the same as 
  test = test ^ 1 // XOR. This is the same as
  test ^= test // XOR. This is the preferred method. It saves 4 bytes in the executable

Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
arduino_code_efficiency.txt · Last modified: 18-06-2020 01:01 by wim