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().

asked Feb 20, 2020 at 23:49
4
  • All code makes a difference to speed and size. Nothing is free. Commented 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? Commented 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. Commented Feb 21, 2020 at 11:51
  • Thanks for clearing that up @Majenko. Commented 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.

answered Feb 21, 2020 at 11:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.