This tutorial is part of: Động cơ servo
Tất cả các video liên quan đến động cơ servo đều được liệt kê ở đây. Các liên kết đến các video khác nằm bên dưới bài viết này.
Controlling a Servo Motor with a Push Button: Move Servo While Button Is Pressed (SPB-3)
This video shows how to control a servo motor using push button and Arduino such that when push button is pressed and keept pressed, the servo moves either from 0° to 180° or from 180° to 0° or set your own values.This tutorial is part of: Động cơ servo
- Điều khiển Servo bằng nút nhấn sử dụng Arduino
- Control a Servo Motor with a Push Button: Move Servo and Return SPB-1
- Control a Servo Motor with a Push Button: Move Servo in One Direction SPB-2
- Điều khiển Servo bằng chiết áp sử dụng Arduino
- Điều khiển Servo bằng chiết áp và LCD1602 sử dụng Arduino
- Controlling Servo Motors Using an Infrared Remote with Arduino
- Điều khiển động cơ servo Arduino bằng cách sử dụng biến trở
- Điều khiển vị trí servo bằng cử chỉ tay cho Arduino
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- Cách sử dụng Servo 360° liên tục với Arduino
- Mã Arduino và Video cho Bộ điều khiển Servo PCA9685 16 kênh 12-bit V1
- Xây dựng Công tắc Bật/Tắt Servo Arduino với Nút Nhấn
272-Code 2 controlling servo motor
Ngôn ngữ: C++
/*
Controlling a servo with Push button with Arduino
this is code #3 to control servo with push button by Robojax (Robojax.com )
code #1 when push button the servo goes from 0° to 180° (or set your angle) and returns back
Watch video for code #1: https://youtu.be/fPrPRZlGdvA
code #2 when push button the servo goes from either from 0° to 180° or from 180° to 0° (or set your angle)
Watch video for code #2: https://youtu.be/T2HMJiy9b_I
code #3 when push button pressed AND keep pressed the servo goes from 0° to 180° (or set your angle)
Watch video for code #3:https://youtu.be/58Qqh60FrMU
code #4 two Push button used one is used to move servo to LEFT direction and the other for RIGHT direciton
Watch video for code #4: https://youtu.be/_uz7YcOzvjU
*
* Written by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
* Date: Dec 13, 2019 at 23:39 in Ajax, Ontario, Canada
*
* Disclaimer: this code is "AS IS" and for educational purpose only.
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
****************************
Get early access to my videos via Patreon and have your name mentioned at end of very
videos I publish on YouTube here: http://robojax.com/L/?id=63 (watch until end of this video to list of my Patrons)
****************************
If you found this tutorial helpful, please support me so I can continue creating
content like this using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define servoPin 3 //~
#define pushButtonPin 2
int angle =90; // initial angle for servo
int angleStep =10;
const int minAngle = 80;
const int maxAngle = 130;
void setup() {
// Servo button demo by Robojax.com
Serial.begin(9600); // setup serial
myservo.attach(servoPin); // attaches the servo on pin 3 to the servo object
pinMode(pushButtonPin,INPUT_PULLUP);
Serial.println("Robojax Servo Button ");
}
void loop() {
while(digitalRead(pushButtonPin) == LOW){
// change the angle for next time through the loop:
angle = angle + angleStep;
// reverse the direction of the moving at the ends of the angle:
if (angle <= minAngle || angle >= maxAngle) {
angleStep = -angleStep;
}
myservo.write(angle); // move the servo to desired angle
Serial.print("Moved to: ");
Serial.print(angle); // print the angle
Serial.println(" degree");
delay(100); // waits for the servo to get there
}// while
}//loop
Tài nguyên & tài liệu tham khảo
Chưa có tài nguyên nào.
Tập tin📁
Không có tệp nào khả dụng.