질문게시판 > 아두이노 피아노 관련 문의 드립니다.

TODAY782 TOTAL340,645
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 아두이노 피아노 관련 문의 드립니다.

페이지 정보

작성자 싼타공룡 작성일2018-11-21 19:41 조회64회 댓글0건

본문

	

안녕하세요.

아두이노를 이용하여 식물or과일 연주기를 만들고 있습니다.

예전에 적외선 센서를 연결하여 센서를 터치하면 연주되는 피아노를 만들었어요.

이것을 적외선 센서를 제외하고

직접 식물에 연결하여 저항값으로 연주되는 피아노를 만들고 싶습니다.

어떻게 수정해야 할까요?

 

/*

  2-12-2011

  Spark Fun Electronics 2011

  Nathan Seidle

  Updated to Arduino 1.01 by Marc "Trench" Tschudin

 

  This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 

  This code works with the VS1053 Breakout Board and controls the VS1053 in what is called Real Time MIDI mode.

  To get the VS1053 into RT MIDI mode, power up the VS1053 breakout board with GPIO0 tied low, GPIO1 tied high.

 

  I use the NewSoftSerial library to send out the MIDI serial at 31250bps. This allows me to print regular messages

  for debugging to the terminal window. This helped me out a ton.

 

  5V : VS1053 VCC

  GND : VS1053 GND

  D3 (SoftSerial TX) : VS1053 RX

  D4 : VS1053 RESET

 

  Attach a headphone breakout board to the VS1053:

  VS1053 LEFT : TSH

  VS1053 RIGHT : RSH

  VS1053 GBUF : GND

 

  When in the drum bank (0x78), there are not different instruments, only different notes.

  To play the different sounds, select an instrument # like 5, then play notes 27 to 87.

 

  To play "Sticks" (31):

  talkMIDI(0xB0, 0, 0x78); //Bank select: drums

  talkMIDI(0xC0, 5, 0); //Set instrument number

  //Play note on channel 1 (0x90), some note value (note), middle velocity (60):

  noteOn(0, 31, 60);

 

*/

 

#include <SoftwareSerial.h>

 

SoftwareSerial mySerial(2, 3); // RX, TX

 

byte note = 0; //The MIDI note value to be played

byte resetMIDI = 4; //Tied to VS1053 Reset line

byte ledPin = 13; //MIDI traffic inidicator

int  instrument = 9;  // 5,8,9:piano,11,12,18 36 :base drum,0:drum

 

//Send a MIDI note-on message.  Like pressing a piano key

//channel ranges from 0-15

void noteOn(byte channel, byte note, byte attack_velocity) {

  talkMIDI( (0x90 | channel), note, attack_velocity);

}

 

//Send a MIDI note-off message.  Like releasing a piano key

void noteOff(byte channel, byte note, byte release_velocity) {

  talkMIDI( (0x80 | channel), note, release_velocity);

}

 

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127

void talkMIDI(byte cmd, byte data1, byte data2) {

  digitalWrite(ledPin, HIGH);

  mySerial.write(cmd);

  mySerial.write(data1);

 

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes

  //(sort of: http://253.ccarh.org/handout/midiprotocol/)

  if ( (cmd & 0xF0) <= 0xB0)

    mySerial.write(data2);

 

  digitalWrite(ledPin, LOW);

}

 

void setup() {

  Serial.begin(57600);

 

  //Setup soft serial for MIDI control

  mySerial.begin(31250);

 

  //Reset the VS1053

  pinMode(resetMIDI, OUTPUT);

  digitalWrite(resetMIDI, LOW);

  delay(100);

  digitalWrite(resetMIDI, HIGH);

  delay(100);

  talkMIDI(0xB0, 0x07, 127); //0xB0 is channel message, set channel volume to near max (127)

 

  for (int pin = 5; pin < 10; pin++) {

    pinMode(pin, INPUT); // IR

    delay(10);

  }

 

}

 

void loop() {

  //Demo Basic MIDI instruments, GM1

  //=================================================================

  Serial.println("Basic Instruments");

  talkMIDI(0xB0, 0, 0x00); //Default bank GM1

 

  //Change to different instrument

 

 

  talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

 

  //Play notes from F#-0 (30) to F#-5 (90):

 

  if (analogRead(0) < 500)

  {

    noteOn(0, 30, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  if (analogRead(1) < 500)

  {

    noteOn(0, 31, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  if (analogRead(2) < 500)

  {

    noteOn(0, 32, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  if (analogRead(3) < 500)

  {

    noteOn(0, 33, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  if (analogRead(4) < 500)

  {

    noteOn(0, 34, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  if (analogRead(5) < 500)

  {

    noteOn(0, 35, 60);//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):

    delay(500);

  }

  else

  {

    noteOff(0, 32, 60);

 

  }

 

 

 

 

}

 

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 0

조회수 64

등록된 댓글이 없습니다.

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
게시물 검색

Privacy Policy
MCU BASIC ⓒ 2017
모바일버전으로보기