Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

StickC PWM

PWMはアナログ信号を生成し、サーボやブザーを駆動するために使用されます

ledcSetup()

機能です:

PWMチャンネル、周波数、解像度を設定します

原型関数です:

void ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits)

ledcAttachPin()

機能です:

LEDCチャネルを指定のIOポートにバインディングして出力を行います

原型関数です:

void ledcAttachPin(uint8_t pin, uint8_t channel)

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <M5StickC.h>

void setup() {
  M5.begin();
  ledcSetup(8, 1,10);  
          // Set the frequency of LEDC channel 8 to 1 and the resolution to
          // 10 bits, that is, the duty cycle can be selected from 0 to
          // 1023. Set LEDC channel 8 frequency to 1, resolution to 10 bits, meaning the duty cycle can range from 0 to 1023.
  ledcAttachPin(32,8);
          // Set LEDC channel 8 to output on IO32.  Set LEDC channel 8 for output on IO32.
}

void loop() {}

ledWrite()

機能です:

channelチャネルにデューティデューティサイクルを書き込みます。

原型関数です:

void ledcWrite(uint8_t channel, uint32_t duty)

使用例です:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <M5StickC.h>
int freq = 1800;
int channel = 0;
int resolution_bits = 8;
int buzzer = 2;

void setup() {
  M5.begin();
  ledcSetup(channel, freq, resolution_bits);
  ledcAttachPin(buzzer, channel);
}
void loop() {
    ledcWrite(channel, 128);
    delay(1000);
    ledcWrite(channel, 0);
    delay(1000);
}
Page Tools
PDF
On This Page