0

I'm making an IR Macro keyboard, and about 10% of the code is dedicated to the Keyboard commands, would having Keyboard.begin() and Keyboard.end() in the method responsible for typing make any difference to the speed or size? My code:

void decodeCode(){ // send the macros.
  int pos = 0;
  for(int i = 0; i<output.length(); i++){
    if(output.charAt(i) == '$' && i!=output.length()-1){ //the $ is a symbol for "$pecial" characters
      i++;
      specialDecodeChar(output.charAt(i));
    }
    else if(output.charAt(i) == '%'){
      Keyboard.releaseAll();
    }
    else{
      Keyboard.press(output.charAt(i));
    }
  }
  Keyboard.releaseAll();
}

I currently have Keyboard.begin() in setup().

4
  • All code makes a difference to speed and size. Nothing is free.
    – Majenko
    Feb 21, 2020 at 0:31
  • 1
    keyboard.begin() is probably a constructor and .end is likely the destuctor. We don't know for sure because not all your code is here. Usually a constructor is run once during the life of a program. And, well, for an embedded program, the destuctor is sometimes just overlooked. So, the question to be answered: Why would you need to make calls to these functions over and over?
    – st2000
    Feb 21, 2020 at 2:57
  • @st2000 Keyboard.begin() and keyboard.end() are not constructors or destructors. They are normal functions typically called from setup, or wherever else you want to start or stop keyboard functionality. However they happen to be empty functions.
    – Majenko
    Feb 21, 2020 at 11:51
  • Thanks for clearing that up @Majenko.
    – st2000
    Feb 21, 2020 at 12:37

1 Answer 1

0

The Keyboard::begin() and Keyboard::end() functions, if you actually look at the code are empty functions. They do nothing.

In theory the compiler should just optimise them out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.