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()
.
-
All code makes a difference to speed and size. Nothing is free.Majenko– Majenko2020年02月21日 00:31:04 +00:00Commented Feb 21, 2020 at 0:31
-
1keyboard.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– st20002020年02月21日 02:57:33 +00:00Commented 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– Majenko2020年02月21日 11:51:35 +00:00Commented Feb 21, 2020 at 11:51
-
Thanks for clearing that up @Majenko.st2000– st20002020年02月21日 12:37:56 +00:00Commented Feb 21, 2020 at 12:37
1 Answer 1
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.