細かい過程ばかり記事にあげている。
最終の一番いいところをさらりと流せばいいのに。
自動演奏の準備をしているところだけど、その間の繋ぎとして、この動画を公開することにした。
くどくなるので伏せておいた方がいいのかなとも思ったけど、公開することにした。
また、タラタラとプログラムを書いた。
これで、とりあえずは動いてくれているけど。
#include <Psx.h>
#include <Servo.h>
#define dataPin 8
#define cmndPin 9
#define attPin 11
#define clockPin 10
Psx Psx;
unsigned int data = 0;
int deg1 = 35;
int deg2 = 67;
int deg3 = 50;
int num = 0;
Servo arm_1st;
Servo arm_2nd;
Servo arm_3rd;
Servo chord_G;
Servo chord_D;
Servo chord_C;
Servo chord_Em;
void setup(){
arm_1st.attach(2,544,1500);
arm_2nd.attach(3,544,1500);
arm_3rd.attach(4,544,1500);
Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10);
// Serial.begin(9600);
arm_1st.write(90);
delay(10);
arm_2nd.write(170);
delay(10);
arm_3rd.write(150);
delay(500);
chord_G.attach(5,544,1500);
chord_D.attach(6,544,1500);
chord_C.attach(7,544,1500);
chord_Em.attach(12,544,1500);
delay(500);
chord_G.write(30);
delay(30);
chord_D.write(140);
delay(30);
chord_C.write(140);
delay(30);
chord_Em.write(30);
delay(30);
chord_G.detach();
chord_D.detach();
chord_C.detach();
chord_Em.detach();
}
void loop(){
data = Psx.read();
// Serial.println(data);
if (data & psxStrt)
{
START();
}
else if (data & psxUp)
{
num = 0;
}
else if (data & psxDown)
{
num = 1;
}
else if (data & psxL1)
{
num = 2;
}
else if (data & psxL2)
{
num = 3;
}
else if (data & psxO)
{
G();
}
else if (data & psxX)
{
D();
}
else if (data & psxSqu)
{
C();
}
else if (data & psxTri)
{
Em();
}
delay(300);
}
void START()
{
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(10);
}
void PLAY()
{
if (num == 0) {
PLAY_long();
}
else if (num == 1) {
PLAY_short();
}
else if (num == 2) {
PLAY_short_long();
}
else if (num == 3) {
PLAY_short_press();
}
}
void PLAY_long()
{
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2-63);
delay(10);
arm_1st.write(deg1-20);
delay(10);
arm_3rd.write(deg3+90);
delay(500);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(10);
}
void PLAY_short()
{
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2-43);
delay(10);
arm_1st.write(deg1-20);
delay(10);
arm_3rd.write(deg3+60);
delay(200);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(10);
}
void PLAY_short_long()
{
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2-43);
delay(10);
arm_1st.write(deg1-20);
delay(10);
arm_3rd.write(deg3+60);
delay(250);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(250);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2-63);
delay(10);
arm_1st.write(deg1-20);
delay(10);
arm_3rd.write(deg3+90);
delay(300);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(10);
}
void PLAY_short_press()
{
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2-43);
delay(10);
arm_1st.write(deg1-20);
delay(10);
arm_3rd.write(deg3+60);
delay(200);
arm_2nd.write(10);
delay(10);
arm_1st.write(120);
delay(150);
arm_3rd.write(35);
delay(700);
arm_1st.write(deg1);
delay(10);
arm_2nd.write(deg2);
delay(10);
arm_3rd.write(deg3);
delay(10);
}
void G()
{
chord_G.attach(5,544,1500);
delay(10);
chord_G.write(95);
delay(300);
PLAY();
delay(300);
chord_G.write(30);
delay(50);
chord_G.detach();
}
void D()
{
chord_D.attach(6,544,1500);
delay(10);
chord_D.write(70);
delay(300);
PLAY();
delay(300);
chord_D.write(140);
delay(50);
chord_D.detach();
}
void C()
{
chord_C.attach(7,544,1500);
delay(10);
chord_C.write(75);
delay(300);
PLAY();
delay(300);
chord_C.write(140);
delay(50);
chord_C.detach();
}
void Em()
{
chord_Em.attach(12,544,1500);
delay(10);
chord_Em.write(90);
delay(300);
PLAY();
delay(300);
chord_Em.write(30);
delay(50);
chord_Em.detach();
}