Created
February 15, 2021 13:53
-
-
Save KeitetsuWorks/2ee6a26d495f7301520fcbb02aafa5bc to your computer and use it in GitHub Desktop.
Servo Motors Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file servos.ino | |
| * @brief Servo Motors Controller | |
| * @author Keitetsu | |
| * @date 2021/02/15 | |
| * @copyright Copyright (c) 2021 Keitetsu | |
| * @par License | |
| * This software is released under the MIT License. | |
| */ | |
| #include <Servo.h> | |
| #define SERVOS_NUM 3 /**< サーボモータの数 */ | |
| #define SERVO_0_PIN 13 /**< サーボモータ0 */ | |
| #define SERVO_1_PIN 12 /**< サーボモータ1 */ | |
| #define SERVO_2_PIN 11 /**< サーボモータ2 */ | |
| /** | |
| * @brief サーボモータ接続ピンのリスト | |
| */ | |
| uint8_t servo_pins[SERVOS_NUM] = { | |
| SERVO_0_PIN, | |
| SERVO_1_PIN, | |
| SERVO_2_PIN}; | |
| /** | |
| * @brief サーボモータ | |
| */ | |
| Servo servos[SERVOS_NUM]; | |
| /** | |
| * @brief セットアップ関数 | |
| */ | |
| void setup() | |
| { | |
| for (int servo_no = 0; servo_no < SERVOS_NUM; servo_no++) { | |
| // 各サーボモータにサーボモータ接続ピンを割り当てる | |
| servos[servo_no].attach(servo_pins[servo_no]); | |
| } | |
| } | |
| /** | |
| * @brief ループ関数 | |
| */ | |
| void loop() | |
| { | |
| // 0度から180度方向へ回転 | |
| for (int pos = 0; pos <= 180; pos++) { | |
| for (int servo_no = 0; servo_no < SERVOS_NUM; servo_no++) { | |
| // 各サーボモータの角度を設定 | |
| servos[servo_no].write(pos); | |
| } | |
| delay(15); | |
| } | |
| // 回転方向を逆転し,180度から0度方向へ回転 | |
| for (int pos = 180; pos >= 0; pos--) { | |
| for (int servo_no = 0; servo_no < SERVOS_NUM; servo_no++) { | |
| // 各サーボモータの角度を設定 | |
| servos[servo_no].write(pos); | |
| } | |
| delay(15); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment