###前提・実現したいこと
Arduino nanoでサーボとLEDと効果音(raw)を動作させるコードを作っています。
コンパイルすると下記のエラーメッセージがでます。
exit status 1
'play' was not declared in this scope
最初に作ったコードはエラーはでませんでした。
###発生している問題・エラーメッセージ
exit status 1 'play' was not declared in this scope
###該当のソースコード
//動作確認済み。コンパイルもOK
#include <Servo.h>
Servo myservo;
int pos = 100;
int speakerPin = 3;
int ledpin5 = 5;
const uint8_t sample05[] PROGMEM = {
0x7b,0x71,0x78,0xff,0x9e,0x00,0xe0,0x72,0x45,0x7f,0x88,0xae,0xa1,0xb3,0xa6,0xaf,
0x99,0x98,0x9b,0x95,0xa0,0xb5,0xd0,0xa3,0x00,0x00,0x00,0x98,0xcc,0xff,0xff,0xff,
0xd0,0xff,0xff,0xb3,0xae,0xdd,0xff,0xa6,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
・・・・・・
0x80,0x80,0x80,0x80,0x80,0x7f,0x80,0x7f,0x80
};
unsigned int sample05_len = 9000;
void setup() {
myservo.attach(9); // サーボのピンを9番に接続
pinMode(ledpin5, OUTPUT);
{
pinMode(3,OUTPUT);
analogWrite( speakerPin, 255);
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS20);
play();}
}
void play() {
for (int i = 0; i < sample05_len; i++) {
OCR2B = pgm_read_byte_near(&sample05[i]);
delayMicroseconds(160);
}
}
void loop() {
digitalWrite(ledpin5, HIGH);
delay(1000);
for (pos = 99; pos <= 150; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 150; pos >= 30; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 30; pos <= 99; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
//エラーメッセージがでるコード #include <Servo.h> int mid_Pos=90; int max_Pos=128; // Bigger value would make it go to further end int min_Pos=50; // smaller value would make it go to another end further. int LED_Power=0; int LED_NormalPower=20; int LED_MaxPower=245; int random_num; int speakerPin = 5; Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = mid_Pos; // variable to store the servo position int ledpin = 3; //Pin for LED, with PWM control const uint8_t sample05[] PROGMEM = { 0x7b,0x71,0x78,0xff,0x9e,0x00,0xe0,0x72,0x45,0x7f,0x88,0xae,0xa1,0xb3,0xa6,0xaf, 0x99,0x98,0x9b,0x95,0xa0,0xb5,0xd0,0xa3,0x00,0x00,0x00,0x98,0xcc,0xff,0xff,0xff, 0xd0,0xff,0xff,0xb3,0xae,0xdd,0xff,0xa6,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ・・・・・・ 0x80,0x80,0x80,0x80,0x80,0x7f,0x80,0x7f,0x80 }; unsigned int sample05_len = 9000; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object pinMode(ledpin, OUTPUT); randomSeed(analogRead(0)); pinMode(3,OUTPUT); analogWrite( speakerPin, 255); TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); TCCR2B = _BV(CS20); play();} } void play() { for (int i = 0; i < sample05_len; i++) { OCR2B = pgm_read_byte_near(&sample05[i]); delayMicroseconds(160); } } void loop() { int eyeMoveTime=0; int maxEyeMoveTime=25; startUp(); normalMove(); delay(500); random_num=0; for (eyeMoveTime=0; eyeMoveTime<maxEyeMoveTime;eyeMoveTime++){ if (random_num>50){ //Panic Mode code panicMove(); } else { // Normal Mode //normalMove(); randomNormalMove(); } random_num=random(0, 100); } LED_rampDown(); delay(5000); }
###試したこと
上のコードに対し、下のコードに変更したところ、
exit status 1
'play' was not declared in this scope
となってしまいました。
どなたか、コードの間違いを訂正してくださる方、よろしくお願いいします。。
###補足情報(言語/FW/ツール等のバージョンなど)
sample のRAWファイルは9993 bytesです。。
LEDが光る前にRAWファイルを再生 サーボが動く・・
つまり、loopの中に「RAW再生→LED点灯(明滅)→サーボも稼働→LED消灯→RAW再生→LED・・」
としたいのです。。
お手数おかけします。
スケッチの添削願います。。
追記です。
#include <Servo.h>
int mid_Pos=90;
int max_Pos=128; // Bigger value would make it go to further end
int min_Pos=50; // smaller value would make it go to another end further.
int LED_Power=0;
int LED_NormalPower=20;
int LED_MaxPower=245;
int random_num;
int speakerPin = 5;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = mid_Pos; // variable to store the servo position
int ledpin = 3; //Pin for LED, with PWM control
const uint8_t sample05[] PROGMEM = {
0x7b,0x71,0x78,0xff,0x9e,0x00,0xe0,0x72,0x45,0x7f,0x88,0xae,0xa1,0xb3,0xa6,0xaf,
0x99,0x98,0x9b,0x95,0xa0,0xb5,0xd0,0xa3,0x00,0x00,0x00,0x98,0xcc,0xff,0xff,0xff,
・・・・・・・
0x7f,0x80,0x7f,0x80,0x7f,0x80,0x80,0x80,0x80,0x7f,0x7f,0x7f,0x7f,0x80,0x80,0x7f,
0x80,0x80,0x80,0x80,0x80,0x7f,0x80,0x7f,0x80
};
unsigned int sample05_len = 6000;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(ledpin, OUTPUT);
randomSeed(analogRead(0));
pinMode(3,OUTPUT);
analogWrite( speakerPin, 255);
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS20);
play();
}
}
}
void loop() {
int eyeMoveTime=0;
int maxEyeMoveTime=25;
void play() {
for (int i = 0; i < sample05_len; i++) {
OCR2B = pgm_read_byte_near(&sample05[i]);
delayMicroseconds(160);
startUp();
normalMove();
delay(500);
random_num=0;
for (eyeMoveTime=0; eyeMoveTime<maxEyeMoveTime;eyeMoveTime++){
if (random_num>50){ //Panic Mode code
panicMove();
} else { // Normal Mode
//normalMove();
randomNormalMove();
}
random_num=random(0, 100);
}
LED_rampDown();
delay(5000);
}
/////
上記のようにすると
'play' was not declared in this scope
となってしまいます。
単純に真ん中のスケッチからカット&ペーストしただけです。
これでは、うまく働かないので、困っておりまして、質問させていただきました。
回答1件
あなたの回答
tips
プレビュー