Hi,
I've recently started trying to create some Arduino libraries so that I can abstract things that I am doing in my sketches so that I may use them again in other sketches more effectively and quickly. However, it seems that the libraries upset my program when I try implementing them - it's very inconsistent.
For example, I am using a Fergilli Linear Actuator L12 with PWM on Arduino Mega. When I run this code in the sketch, it works just fine:
void press() {
go_down();
go_up();
}
void go_down() {
for (pos = largest_posn; pos > smallest_posn-1; pos--)
{
analogWrite(actuatorPin, pos);
delay(actuator_delay_time);
}
}
void go_up() {
for (pos = smallest_posn; pos < largest_posn-1; pos++)
{
analogWrite(actuatorPin, pos);
delay(actuator_delay_time);
}
}
But when I move this code into an ActuatorLibrary, and make an Actuator.h with just the methods Acuator(int actuatorPin) and press() (I moved go_down and go_up into the press() method), and then add it to my loop with a delay of 5 seconds, the actuator just moves up and down without any regard to my delay or the rest of my program:
Actuator actuator(actuatorPin);
void setup() {
Serial.begin(9600);
}
void loop {
actuator.press();
delay(5000);
}
I'd really appreciate the feedback. I'm trying to create helper libraries for an XY stepper axis and the PixyCMUCam5 to help with reducing the size of my sketches, but they all seem to have errors. I wonder if there is something I'm doing wrong?