I am fairly new to the Arduino world and need help with an issue with a code that I have written to control a servo and a linear actuator.
Background/function:
The servo and the linear actuator are independently controlled via two momentary switches.
Both the servo and the linear actuator are coded to go to a set parameter (angle or distance) with a push of the button and then return with a subsequent push of the button.
Servo is a Parallax Servo
Linear Actuator is a Actuonix P-16-P series connected to an Actuonix LAC board.
If I upload the codes independently (one to just control the servo or one to just control the linear actuator) the code works perfectly.
When I try to fuse the two codes together only the servo is functioning and I cannot get any response from the linear actuator.
I have ran verification on the code and do not get any errors.
Any help with this would be greatly appreciated.
P.S. I apologize if this is in the wrong category or if my code does not display properly.
[table][tr][tt][size=0.8em]Code: see how to post code [/size][/tt][hr][/tr][tr][tt][size=0.8em]#include[nobbc] <[/nobbc]Servo[nobbc].h>[/nobbc]
#include[nobbc] <Bounce2.h>[/nobbc]
[nobbc]//defines[/nobbc]
[nobbc][/nobbc]Servo[nobbc] myservo; [/nobbc][nobbc]// create servo object to control expansion servo[/nobbc]
[nobbc][/nobbc]Servo[nobbc] LINEARACTUATOR; [/nobbc][nobbc]// create servo objects to control the linear actuator[/nobbc]
const int[nobbc] LINEAR_ACTUATOR_PIN = 5; [/nobbc][nobbc]//Linear Actuator Digital Pin[/nobbc]
const int[nobbc] BUTTON_PIN = 4; [/nobbc][nobbc]// the number of the pushbutton pin[/nobbc]
[nobbc]// variables will change:[/nobbc]
int[nobbc] buttonState = 0; [/nobbc][nobbc]// variable for reading the pushbutton status for the servo[/nobbc]
int[nobbc] linearValue = 1000; [/nobbc][nobbc]// current positional value being sent to the linear actuator. [/nobbc]
[nobbc]Bounce debouncer = Bounce(); [/nobbc][nobbc]// debouncing object for linear actuator push button[/nobbc]
#define[nobbc] servoPin 3 [/nobbc][nobbc]//~ PWM for servo[/nobbc]
#define[nobbc] ButtonSPin 2 [/nobbc][nobbc]//input button for expansion servo[/nobbc]
int[nobbc] ButtonSState = 0;[/nobbc]
int[nobbc] buttonSPushed = 0;[/nobbc]
int[nobbc] angle =0; [/nobbc][nobbc]// initial angle for servo[/nobbc]
int[nobbc] angleStep =30;[/nobbc]
const int[nobbc] minAngle = 0;[/nobbc]
const int[nobbc] maxAngle = 90;[/nobbc]
void setupnobbc {[/nobbc]
[nobbc] myservo.[/nobbc]writenobbc;[/nobbc]
[nobbc] myservo.[/nobbc]attachnobbc; [/nobbc][nobbc]// attaches the servo on pin 3 to the servo object[/nobbc]
pinModenobbc; [/nobbc]
[nobbc]//initialize servo/linear actuator objects[/nobbc]
[nobbc] LINEARACTUATOR.[/nobbc]attach[nobbc](LINEAR_ACTUATOR_PIN, 1000, 1500); [/nobbc][nobbc]// attaches/activates the linear actuator as a servo object [/nobbc]
[nobbc]// initialize the pushbutton pin as an input with internal pullup:[/nobbc]
pinMode[nobbc](BUTTON_PIN, [/nobbc]INPUT_PULLUP[nobbc]); [/nobbc]
[nobbc]// After setting up the button, setup the Bounce instance:[/nobbc]
[nobbc] debouncer.[/nobbc]attachnobbc;[/nobbc]
[nobbc] debouncer.interval(5); [/nobbc][nobbc]// interval in ms[/nobbc]
[nobbc]//use the writeMicroseconds to set the linear actuators to their default positions[/nobbc]
[nobbc] LINEARACTUATOR.[/nobbc]writeMicrosecondsnobbc; [/nobbc]
}
void loopnobbc {[/nobbc]
[nobbc]//servo control[/nobbc]
if(digitalReadnobbc == [/nobbc]LOW[nobbc]){[/nobbc]
buttonSPushed = 1;
}
ifnobbc{[/nobbc]
[nobbc]// change the angle for next time through the loop:[/nobbc]
angle = angle + angleStep;
[color=#434F54][nobbc]// reverse the direction of the moving at the ends of the angle:[/nobbc][/color]
[color=#5E6D03]if[/color][nobbc] (angle <= minAngle || angle >= maxAngle) {[/nobbc]
angleStep = -angleStep;
buttonSPushed = 0;
}
[nobbc] myservo.[/nobbc]writenobbc; [/nobbc][nobbc]// move the servo to desired angle[/nobbc]
delaynobbc; [/nobbc][nobbc]// waits for the servo to get there[/nobbc]
}
[nobbc]//LA Control[/nobbc]
[nobbc]// Update the Bounce instance :[/nobbc]
debouncer.update();
[nobbc]// Get the updated value :[/nobbc]
int[nobbc] buttonValue = debouncer.[/nobbc]readnobbc;[/nobbc]
if[nobbc] ( debouncer.fell() ) [/nobbc][nobbc]// if the button was pressed[/nobbc]
{
if[nobbc] (linearValue == 1000) [/nobbc][nobbc]//if the box is set to close[/nobbc]
{
[nobbc] linearValue = 1500; [/nobbc][nobbc]//set box to open[/nobbc]
}
else if[nobbc] (linearValue == 1500) [/nobbc][nobbc]//if the box was set to open[/nobbc]
{
[nobbc] linearValue = 1000; [/nobbc][nobbc]//set box to close[/nobbc]
}
}
}[/size][/tt][/tr][/table]