1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5C6)Servo(サーボ)で遊ぶ。(PWM)(M5Nano C6)

Last updated at Posted at 2024-10-11

x 過去ログを見よ!!
x 業務連絡 マルチメディア飲み会あるよ(絶滅メディア博物館) なんのこと?
x サーボを繋ぐ時は、必ず絶縁してください。
x サーボをパソコンに繋いだままやるとパソコンが破壊されます。
x モーター、コイル等、逆起電力で高電圧が発生する時の安全対策は、各自実行してください。
x 最低でも、試す時は、モバイルバッテリを使用してください。
x モータ系の力学装置系をなぜ、あまりやらないのかは、まず、物理的にお金がかかる、いろいろ、危険であるから

目的
秋月で買った。
SG-90(PWMラジコンサーボ)を使い旗を振る。

結果

o_coq506.jpg

o_coq507.jpg

プログラム



//PWM_ledcWrite_servo_C6_1


//インクルド
#include<Arduino.h>


//定義
//使い方 SOのマクロに0から180を設定すると
//PWMの間隔の値が返る
//        a = SO(i);
//        //a = SO(180-i);
#define V_0    500
#define V_180 2400
#define Width_0_180   (V_180-V_0)
#define Wavelength_1count (((1000000/50)*1024)/4096)
#define T_MIN ((V_0*1024)/Wavelength_1count)
#define T_MAX ((V_180*1024)/Wavelength_1count)
#define HH  ((T_MAX-T_MIN)*1024)/180
#define SO(AA) (T_MIN+(((AA)*(HH))>>10))

//PWMのポート、周期、分解度のビット数
#define PWM_PIN 1
#define FREQUENCY 50
#define RESOLUTION 12


//初期化
void setup() {

  //出力ピンの初期化
  pinMode(PWM_PIN, OUTPUT);

  // PWM設定(ピン番号, 周波数, 分解能)
  ledcAttach(PWM_PIN, FREQUENCY, RESOLUTION);
  
} //setup


//メインループ
void loop() {

  // DUTY比を指定して、ポートに対して実行 0°
  ledcWrite(PWM_PIN, SO(0));
  delay(2000); //2秒待つ

  // DUTY比を指定して、ポートに対して実行 180°
  ledcWrite(PWM_PIN, SO(180));
  delay(2000); //2秒待つ

} //loop


1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?