Newer
Older
M5StickCPlus_FactoryTest2022 / SampleSrc / servohat01.ino
@motoki miura motoki miura on 10 May 2022 633 bytes SampleSource
#define MLOW 5
#define MHIGH 33

void setup() {
  ledcSetup(1, 50, 8); //サーボハット CH1
  ledcAttachPin(26, 1);

  pinMode(10, OUTPUT);
  ledcSetup(2, 100, 8);//LED CH2
  ledcAttachPin(10, 2);
}

void loop() {
  for (int i = MLOW; i <= MHIGH; i = i + 1) {
    ledcWrite(1, i);
    int v = map(i, MLOW, MHIGH, 0, 256); // 範囲5〜33に対するiの値を、範囲0〜256に変換
    ledcWrite(2, v);
    delay(50);
  }
  delay(300);
  for (int i = MHIGH; i >= MLOW; i = i - 1) {
    ledcWrite(1, i);
    int v = map(i, MLOW, MHIGH, 0, 256);
    ledcWrite(2, v);
    delay(20);
  }
  delay(300);
}