Let's say my sketch has a constant "foo=100" and I have a library called "libby" with a function called "funk". Inside of funk there is a variable "boo" that will always be foo/2. My question is, what is the approach that would allow the computation to happen only once even though funk is called many times in the sketch.
I'd have the sketch pass in the value through a constructor or configuration method, and design the sketch so that the value was only passed on once. In your example, calling funk() repeatedly from loop() doesn't make sense; it would be better called once from setup(), or pass the value in via a constructor argument.
PeterH:
I'd have the sketch pass in the value through a constructor or configuration method, and design the sketch so that the value was only passed on once. In your example, calling funk() repeatedly from loop() doesn't make sense; it would be better called once from setup(), or pass the value in via a constructor argument.
I think I understand how to make the computation in the constructor, however I am not at all clear how I should declare the variable "boo" in the libby.cpp and libb.h if I take that approach. Could you provide some guidance?