太鼓のバチを強力なサーボで振り回す。
バチの保持に遊びを持たせてかつ輪ゴムで止めることにより当たったたときの反動を逃がす。
サーボに大電流が流れ電源の電圧降下が起こりMPUがリセットするのを防ぐため電源ラインにダイオード、大容量電解コンデンサを使う。
モバイルバッテリーの自動OFF機能をキャンセルするために150mA程度のパルス負荷回路を付加。
/*
- 太鼓演奏用
- Arduino Pro mini
- 2023.8.15
*/
#include <Servo.h>
#define Sw 2 //スイッチ入力 #define Aoff 6 //オートoff #define Vr 0 //設定VR
#define Base 90 //135 #define P1 20 //p1
Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() { pinMode(Aoff, OUTPUT); digitalWrite(Aoff,LOW);
myservo.attach(5); // attaches the servo on pin 9 to the servo object
pinMode(Sw, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
myservo.write(90); }
#define T 50 //50
void unAutoOff() { static unsigned long t; static boolean f = false;
if(millis()>t){ if(f==false){ //on digitalWrite(Aoff,HIGH); t = millis() + 1000; //アクティブ100ms f = true; }else{ //off digitalWrite(Aoff,LOW); t = millis() + 10000; //休止5sec f = false; } } }
unsigned long t;
void loop() {
myservo.write(Base);
t = millis();
while(digitalRead(Sw)==HIGH){
digitalWrite(LED_BUILTIN, LOW) ;
unAutoOff();
}
int d = analogRead(Vr);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(Aoff,LOW);
if(d>512){
//単打
myservo.write(Base);
delay(T);
myservo.write(Base-40);
delay(150); // waits 15ms for the servo to reach the position
myservo.write(Base);
while(digitalRead(Sw)==LOW){
delay(10);
}
}else{
//連打
myservo.write(Base);
delay(T);
myservo.write(Base-P1);
delay(100); // waits 15ms for the servo to reach the position
while(digitalRead(Sw)==LOW){
d = analogRead(Vr)/3;
myservo.write(Base-P1 +10);
delay(d);
myservo.write(Base-P1);
delay(d);
}
} }
よく構成図がわからないのですが配線図のわかりやすい図はありませんか?部品は買ったのですが?接続部がよくわからないので教えてください。よろしくお願いします