기본적으로 아두이노에... 기본적인 MIDI가 있기 때문에 그 MIDI를  바탕으로 한번 연습해본 거 이다.!!!

아래 코드는 각 음마다 함수처리를 한 것 이다.

int speakpin =9;
int pitch=0;

void setup()
{
  pinMode(1,INPUT);
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  
  pinMode(speakpin,OUTPUT);

}
void loop()
{
  if(digitalRead(1) ==0)
  {
     Do(); 
  }
  if(digitalRead(2) ==0)
  {
      re();
  }
  if(digitalRead(3) ==0)
  {
     mi();
  }
  if(digitalRead(4) ==0)
  {
     la();
  }
  if(digitalRead(5) ==0)
  {
    sol();
  }
  
}

void sol()
{
  pitch = 1276 - analogRead(0);
  digitalWrite(speakpin,1);
  delayMicroseconds(pitch);
  digitalWrite(speakpin,0);
  delayMicroseconds(pitch);
}
void la()
{
  pitch = 1137 - analogRead(0);
  digitalWrite(speakpin,1);
  delayMicroseconds(pitch);
  digitalWrite(speakpin,0);
  delayMicroseconds(pitch);
}
void Do()
{
  pitch = 955 - analogRead(0);
  digitalWrite(speakpin,1);
  delayMicroseconds(pitch);
  digitalWrite(speakpin,0);
  delayMicroseconds(pitch);
}
void re()
{
  pitch = 852 - analogRead(0);
  digitalWrite(speakpin,1);
  delayMicroseconds(pitch);
  digitalWrite(speakpin,0);
  delayMicroseconds(pitch);
}
void mi()
{
  pitch = 759 - analogRead(0);
  digitalWrite(speakpin,1);
  delayMicroseconds(pitch);
  digitalWrite(speakpin,0);
  delayMicroseconds(pitch);
}


'프로그래밍 > Arduino' 카테고리의 다른 글

[Arduino] 분노의 납땜질!!!!  (0) 2012.02.14
[아두이노] LEDs Roulette 2  (0) 2011.12.14
[아두이노] LEDs Roulette 1  (0) 2011.12.14
[아두이노] Spin Motor  (0) 2011.12.14
[아두이노] Multiple LEDs  (0) 2011.12.14