0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5Stack FIRE + BaseX でサーボモータSG90を動かす

0
Posted at

M5Stack FIRE + BaseX を用いて,ボタンAを押すと0度,ボタンBを押すと90度にSG90サーボモータを駆動させる参考プログラム
M5StackFIREサーボモータ.gif

M5StackFIRE_servo_button.ino
#include <M5Stack.h>
#include "BaseX.h"

BASE_X base_x;

void setup() {
  // LCD有効, SD無効, Serial有効, I2C有効
  M5.begin(true, false, true, true); 
  
  delay(500);
  
  M5.Lcd.clear();
  M5.Lcd.setTextSize(2);
  M5.Lcd.println("BaseX Servo Test");
  M5.Lcd.println("A: 0 deg");
  M5.Lcd.println("B: 90 deg");
  M5.Lcd.println("C (Hold): Shutdown");
}

void loop() {
  M5.update();

  // ボタンA:0度
  if (M5.BtnA.wasPressed()) {
    base_x.SetServoAngle(1, 0); // Servo1 ポート
    M5.Lcd.setCursor(0, 100);
    M5.Lcd.println("Servo: 0 deg   ");
  } 
  
  // ボタンB:90度
  if (M5.BtnB.wasPressed()) {
    base_x.SetServoAngle(1, 90); // Servo1 ポート
    M5.Lcd.setCursor(0, 100);
    M5.Lcd.println("Servo: 90 deg  ");
  }

  // ボタンC:2秒長押しでシャットダウン
  if (M5.BtnC.pressedFor(2000)) {
    M5.Lcd.clear(RED);
    M5.Lcd.setCursor(50, 100);
    M5.Lcd.println("SHUTDOWN...");
    delay(1000);
    M5.Power.powerOFF();
  }

  delay(10);
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?