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
Press Button, Move Right, Press Again, Move Left – Lara Grant

Press Button, Move Right, Press Again, Move Left

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

DESCRIPTION: Press button once, both servos move right, push button again, both servos move left.

[code lang=”arduino” light=”true”]
/*
* push button to rotate left
* push button to rotate right
*
* halloween workshop 2012
* source found: http://www.qrong.com/archives/46
* altered by lara grant
*/

#include <Servo.h>

// Set digital pin numbers:
const int servoPin = 7; // The number of the Servo1 pin
const int servoPin2 = 8; // The number of the Servo2 pin
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 myservo1; // Create servo object to control servo1
Servo myservo2; // Create servo object to control servo2

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

void setup() {
myservo1.attach(7); // attaches the servo on pin 7 to the servo object
myservo2.attach(8); // 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);

if (directionState == 0){
//The button is pushed
if (buttonState == LOW) {
directionState = 1;// The direction for the servo is clockwise
for(pos = 0; pos < 180; pos=pos+1) // goes from 0 degrees to 180 degrees in steps of 1 degree
{
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}

}
else if (directionState == 1) {
// The button is pushed
if (buttonState == LOW) {
directionState = 0; // The direction for the servo is anti-clockwise
for(pos = 180; pos>=1; pos=pos-1) // goes from 180 degrees to 0 degrees in steps of 1 degree
{
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
myservo2.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
}

}

[/code]

Leave a Reply