ArduinoとESP32を利用してのサーボモーターの制御


初心者E  2023-11-15 10:42:50  No: 151275

ArduinocloudとESP32を利用して、スマホからスイッチをオンにしたらサーボモーターを動かす、というものを作成したいです。

https://garchiving.com/remote-control-led-flash-test-with-arduino-iot-cloud/#toc2

https://kanpapa.com/today/2022/12/esp32-otafab-study-servo.html
↑のサイトを参考に、設定や一部のプログラムは作成しました。

が、
if(myServo){
の部分で毎回エラーになってしまいます。エラー内容は赤文字かつ、長すぎるので割愛します。

やってみたこと
if(myServo){
の(myServo)の部分をいろいろ変えてみたのですが、変わりませんでした。

以下、問題のプログラム文です。

#include "thingProperties.h"
#include <ESP32Servo.h>

#define SERVO_PIN 5
Servo myServo;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
}

/*
  Since P90Switch is READ_WRITE variable, onP90SwitchChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onP90SwitchChange()  {
    if(myServo){
    servo.write(0);
    delay(500);
    servo.write(180);
    delay(500);
  } else {

  }
}


※返信する前に利用規約をご確認ください。








  このエントリーをはてなブックマークに追加