Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ignition domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /dom953964/wp-includes/functions.php on line 6131

Deprecated: Return type of GD_WordPress_File_Iterator_Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /dom953964/wp-content/plugins/wp_migration-master/classes/iterators.php on line 5

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the health-check domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /dom953964/wp-includes/functions.php on line 6131
Button Press to Move 2 Servos Mirrored – Lara Grant

Button Press to Move 2 Servos Mirrored

INPUT: 1 Momentary Button
OUTPUT: Two Servos – SG90 T Pro Micro Servos

Description: Press button, rotate servo 1 right and servo 2 left hold 1 sec, reverse. Press once for one right/left action. Keep pressing to continue action loop.

[code lang=”arduino” light=”true”]
/*
* push button once – servo 1 rotates forward, servo 2 rotated back, hold 1 sec, reverse
*
* halloween workshop 2012
* lara grant
*/

#include <Servo.h>
#include "ClickButton.h"

// Set digital pin numbers:
const int servoPin = 9; // The number of the right Servo pin facing
const int servoPin2 = 8; // The number of the left Servo pin facing
const int buttonPin = 2; // The number of the Pushbutton pin

int buttonState = 0; // Variable for reading the pushbutton status
int directionState = 0; // Variable for reading direction of the servo

Servo myservo; // Create servo object to control a servo
Servo myservo2;

int pos = 0; // Variable to store the servo position

void setup() {
Serial.begin(9600);
myservo.attach(8); // attaches the servo on pin 8 to the servo object
myservo2.attach(9); // attaches the servo on pin 7 to the servo object
pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as an input
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);

//The button is pushed
if (buttonState == LOW) {

forward();
delay(1000);
reverse();
delay(1000 );
}
}

void forward() {
myservo.write(0);
myservo2.write(180);
}

void reverse() {
myservo.write(180);
myservo2.write(0);
}

[/code]

Leave a Reply