Skip to main content
Arduino

Return to Revisions

2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/

This is a simple solution. All you need to do is declare a global variable (i.e. make it accessible everywhere in your sketch), and then add some additional code to "share" the servo between the different parts of the code.

Code you need:

Your library:

Servo servoname;
void foo() {
 //Some code here!
}
void bar() {
 //More code here!
}

The methods foo() and bar() are irreverent to the code, you just need to declare it.

Your library header file (name.h):

extern Servo servoname;

All you need to do then is import your new library and use servoname. You will have to still call servoname.attach([pin]); before you can use the servo, but then you just need to use the servo.

Source

Anonymous Penguin
  • 6.4k
  • 10
  • 34
  • 62

AltStyle によって変換されたページ (->オリジナル) /