前提・実現したいこと
海外の方がyoutubeにて公開してくださっている資料をもとに、
いくつかのサーボモーターを使用し、動かそうとしています。
参照元: https://youtu.be/Ftt9e8xnKE4
ArduinoIDEにてコンパイルした際に以下のエラーメッセージが発生しました。
(一部個人情報を※にて隠しています)
どこをどう変更すればコンパイルが通るでしょうか?
発生している問題・エラーメッセージ
eye:12:26: error: expected unqualified-id before ')' token Adafruit_PWMServoDriver (); ^ C:\Users\※※※\Documents\Arduino\eye\eye\eye.ino: In function 'void setup()': eye:47:7: error: request for member 'begin' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.begin(); ^~~~~ eye:49:7: error: request for member 'setPWMFreq' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates ^~~~~~~~~~ C:\Users\※※※\Documents\Arduino\eye\eye\eye.ino: In function 'void loop()': eye:96:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(0, 0, lexpulse); ^~~~~~ eye:97:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(1, 0, leypulse); ^~~~~~ eye:101:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(2, 0, 400); ^~~~~~ eye:102:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(3, 0, 240); ^~~~~~ eye:103:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(4, 0, 240); ^~~~~~ eye:104:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(5, 0, 400); ^~~~~~ eye:107:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(2, 0, uplidpulse); ^~~~~~ eye:108:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(3, 0, lolidpulse); ^~~~~~ eye:109:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(4, 0, altuplidpulse); ^~~~~~ eye:110:11: error: request for member 'setPWM' in 'pwm', which is of non-class type 'void(uint32_t, uint32_t, uint32_t) {aka void(long unsigned int, long unsigned int, long unsigned int)}' pwm.setPWM(5, 0, altlolidpulse); ^~~~~~ exit status 1 expected unqualified-id before ')' token
該当のソースコード
#include <Wire.h> #include <Adafruit_PWMServoDriver.h> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); #define SERVOMIN 140 // this is the 'minimum' pulse length count (out of 4096) #define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096) // our servo # counter uint8_t servonum = 0; int xval; int yval; int lexpulse; int rexpulse; int leypulse; int reypulse; int uplidpulse; int lolidpulse; int altuplidpulse; int altlolidpulse; int trimval; const int analogInPin = A0; int sensorValue = 0; int outputValue = 0; int switchval = 0; void setup() { Serial.begin(9600); Serial.println("8 channel Servo test!"); pinMode(analogInPin, INPUT); pinMode(2, INPUT); pwm.begin(); pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates delay(10); } // you can use this function if you'd like to set the pulse length in seconds // e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise! void setServoPulse(uint8_t n, double pulse) { double pulselength; pulselength = 1000000; // 1,000,000 us per second pulselength /= 60; // 60 Hz Serial.print(pulselength); Serial.println(" us per period"); pulselength /= 4096; // 12 bits of resolution Serial.print(pulselength); Serial.println(" us per bit"); pulse *= 1000000; // convert to us pulse /= pulselength; Serial.println(pulse); } void loop() { xval = analogRead(A1); lexpulse = map(xval, 0,1023, 220, 440); rexpulse = lexpulse; switchval = digitalRead(2); yval = analogRead(A0); leypulse = map(yval, 0,1023, 250, 500); reypulse = map(yval, 0,1023, 400, 280); trimval = analogRead(A2); trimval=map(trimval, 320, 580, -40, 40); uplidpulse = map(yval, 0, 1023, 400, 280); uplidpulse -= (trimval-40); uplidpulse = constrain(uplidpulse, 280, 400); altuplidpulse = 680-uplidpulse; lolidpulse = map(yval, 0, 1023, 410, 280); lolidpulse += (trimval/2); lolidpulse = constrain(lolidpulse, 280, 400); altlolidpulse = 680-lolidpulse; pwm.setPWM(0, 0, lexpulse); pwm.setPWM(1, 0, leypulse); if (switchval == HIGH) { pwm.setPWM(2, 0, 400); pwm.setPWM(3, 0, 240); pwm.setPWM(4, 0, 240); pwm.setPWM(5, 0, 400); } else if (switchval == LOW) { pwm.setPWM(2, 0, uplidpulse); pwm.setPWM(3, 0, lolidpulse); pwm.setPWM(4, 0, altuplidpulse); pwm.setPWM(5, 0, altlolidpulse); } Serial.println(trimval); delay(5); }
試したこと
ネット上で検索や翻訳をしてみましたが、お手上げ状態となります。
補足情報
ArduinoIDE 1.8.14を使用。
書き込み先は Miuzei Board Model R3 です。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/06/30 11:11
2021/06/30 12:32
2021/06/30 13:40
2021/06/30 14:58
2021/06/30 15:33
2021/06/30 18:11