안녕하세요 제목그대로 코코아팹에서 본 버튼식 피아노를 만드는 동영상및 파일을 보았습니다.
문득 버튼 식이아니라 스마트폰으로 연동을 해서 하면 어떨가 싶어서 문의를 드렸습니다.
아직 아두이노를 배우고 있다고 말하기 민망하기정도로 아직 학습의 지식은 많이 얕습니다...
제가 소스코드를 짜봤는데 혹시 틀린거나 맞는지 알려주시면 안될까요? (건반이 누름과동시 엘이디도 같이 켜짐)
#include <pitches.h>
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(3,4);
byte CommandLed = '0';
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
int melody[] = {
NOTE_C4,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; tone(8, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
Serial.begin(9600);
Serial.println("Hello!");
BTSerial.begin(9600);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(13, OUTPUT);
}
}
void loop() {
if (BTSerial.available()>0)
{
CommandLed = BTSerial.read();
Serial.write(CommandLed);
if(CommandLed =='1')
{
tone(12,NOTE_C4);
delay(500);
noTone(12);
delay(500);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='2')
{
tone(11,NOTE_D4);
delay(500);
noTone(11);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='3')
{
tone(10,NOTE_E4);
delay(500);
noTone(10);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='4')
{
tone(9,NOTE_F4 );
delay(500);
noTone(9);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='5')
{
tone(9,NOTE_G4 );
delay(500);
noTone(9);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='6')
{
tone(9,NOTE_A4 );
delay(500);
noTone(9);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
}
else if(CommandLed =='7')
{
tone(9,NOTE_B4 );
delay(500);
noTone(9);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
}
else if(CommandLed =='8')
{
tone(9,NOTE_C5 );
delay(500);
noTone(9);
delay(500);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
}
else
{
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
}
}
|