ロボギターでコードを押えてみる(テスト) | ..あちゃ! no mic's

..あちゃ! no mic's

クラウドファンディング予定~2026年度
何度でもチャレンジ!
ただいまソーラーピックアップのテスト中

SANTA no Mix

ロボザックでツクル、ロボットアーム。
ChordBuddyでギターを弾かせてみる実験。

ArduinoのDCジャックから給電しているので、動作が不安定にならないか心配。
かなり発熱しているみたい。
別に、電源を用意しないといけないかなあ。


プレステコントローラで弾くのが面倒だ。
自動演奏してみるのがいいかも。
でも、チューニングが悪いのか、音の響きが、どれも同じ音に聞こえる。

スケッチはもっと簡潔に短くできるけど、わざわざ読んでくれる人のために? タラタラと書いた。
PSXLibraryを使っている。
消費電力を減らすために、Servoのピンを解除している。
これが最善の策かは分からないけど、とりあえず載せておく。


#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;

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 & psxDown)                                       
  {
   PLAY();
  }
  
  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()
{
    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 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();
}