質問編集履歴

2

コピペしたスケッチを追記

2017/11/15 05:06

投稿

takupi-2
takupi-2

スコア7

test CHANGED
File without changes
test CHANGED
@@ -411,3 +411,183 @@
411
411
 
412
412
 
413
413
  スケッチの添削願います。。
414
+
415
+
416
+
417
+ 追記です。
418
+
419
+ #include <Servo.h>
420
+
421
+
422
+
423
+ int mid_Pos=90;
424
+
425
+ int max_Pos=128; // Bigger value would make it go to further end
426
+
427
+ int min_Pos=50; // smaller value would make it go to another end further.
428
+
429
+ int LED_Power=0;
430
+
431
+ int LED_NormalPower=20;
432
+
433
+ int LED_MaxPower=245;
434
+
435
+ int random_num;
436
+
437
+ int speakerPin = 5;
438
+
439
+
440
+
441
+ Servo myservo; // create servo object to control a servo
442
+
443
+
444
+
445
+ // twelve servo objects can be created on most boards
446
+
447
+
448
+
449
+ int pos = mid_Pos; // variable to store the servo position
450
+
451
+
452
+
453
+ int ledpin = 3; //Pin for LED, with PWM control
454
+
455
+
456
+
457
+ const uint8_t sample05[] PROGMEM = {
458
+
459
+ 0x7b,0x71,0x78,0xff,0x9e,0x00,0xe0,0x72,0x45,0x7f,0x88,0xae,0xa1,0xb3,0xa6,0xaf,
460
+
461
+ 0x99,0x98,0x9b,0x95,0xa0,0xb5,0xd0,0xa3,0x00,0x00,0x00,0x98,0xcc,0xff,0xff,0xff,
462
+
463
+ ・・・・・・・
464
+
465
+ 0x7f,0x80,0x7f,0x80,0x7f,0x80,0x80,0x80,0x80,0x7f,0x7f,0x7f,0x7f,0x80,0x80,0x7f,
466
+
467
+ 0x80,0x80,0x80,0x80,0x80,0x7f,0x80,0x7f,0x80
468
+
469
+ };
470
+
471
+
472
+
473
+ unsigned int sample05_len = 6000;
474
+
475
+
476
+
477
+ void setup() {
478
+
479
+
480
+
481
+ myservo.attach(9); // attaches the servo on pin 9 to the servo object
482
+
483
+
484
+
485
+ pinMode(ledpin, OUTPUT);
486
+
487
+ randomSeed(analogRead(0));
488
+
489
+
490
+
491
+ pinMode(3,OUTPUT);
492
+
493
+ analogWrite( speakerPin, 255);
494
+
495
+
496
+
497
+
498
+
499
+ TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
500
+
501
+ TCCR2B = _BV(CS20);
502
+
503
+
504
+
505
+ play();
506
+
507
+
508
+
509
+ }
510
+
511
+
512
+
513
+
514
+
515
+ }
516
+
517
+ }
518
+
519
+
520
+
521
+ void loop() {
522
+
523
+
524
+
525
+ int eyeMoveTime=0;
526
+
527
+ int maxEyeMoveTime=25;
528
+
529
+
530
+
531
+ void play() {
532
+
533
+ for (int i = 0; i < sample05_len; i++) {
534
+
535
+ OCR2B = pgm_read_byte_near(&sample05[i]);
536
+
537
+ delayMicroseconds(160);
538
+
539
+
540
+
541
+ startUp();
542
+
543
+ normalMove();
544
+
545
+ delay(500);
546
+
547
+ random_num=0;
548
+
549
+ for (eyeMoveTime=0; eyeMoveTime<maxEyeMoveTime;eyeMoveTime++){
550
+
551
+ if (random_num>50){ //Panic Mode code
552
+
553
+ panicMove();
554
+
555
+ } else { // Normal Mode
556
+
557
+ //normalMove();
558
+
559
+ randomNormalMove();
560
+
561
+ }
562
+
563
+
564
+
565
+ random_num=random(0, 100);
566
+
567
+ }
568
+
569
+
570
+
571
+ LED_rampDown();
572
+
573
+
574
+
575
+ delay(5000);
576
+
577
+ }
578
+
579
+
580
+
581
+ /////
582
+
583
+ 上記のようにすると
584
+
585
+ 'play' was not declared in this scope
586
+
587
+ となってしまいます。
588
+
589
+
590
+
591
+ 単純に真ん中のスケッチからカット&ペーストしただけです。
592
+
593
+ これでは、うまく働かないので、困っておりまして、質問させていただきました。

1

スケッチの添削

2017/11/15 05:06

投稿

takupi-2
takupi-2

スコア7

test CHANGED
File without changes
test CHANGED
@@ -394,4 +394,20 @@
394
394
 
395
395
  ###補足情報(言語/FW/ツール等のバージョンなど)
396
396
 
397
+ sample のRAWファイルは9993 bytesです。。
398
+
399
+
400
+
401
+ LEDが光る前にRAWファイルを再生 サーボが動く・・
402
+
403
+ つまり、loopの中に「RAW再生→LED点灯(明滅)→サーボも稼働→LED消灯→RAW再生→LED・・」
404
+
397
- より詳細な情報
405
+ としたいのです。。
406
+
407
+
408
+
409
+ お手数おかけします。
410
+
411
+
412
+
413
+ スケッチの添削願います。。