코코아팹은 누구나 창의적 아이디어를 현실로 만들어 낼 수 있도록
만들고, 공유하고, 배울 수 있는 터전이
되고자 합니다.
아이디와 비밀번호를 잊으셨나요?아이디 / 비밀번호 찾기
코코아팹 회원이 아니신가요? 회원가입
2014-12-24 13:14:54
NO | 부품명 | 수량 | 상세설명 |
1 | 아두이노 미니 | 1 | 아두이노 미니 |
2 | FTDI 232r USB | 1 | TTL Serial to USB |
3 | RGB LED | 1 | 7 SMD RGB LED - DF Robot |
4 | 피에조부저 | 1 | 피에조부저 |
5 | 슬라이드 스위치 | 1 | 3핀 스위치 |
6 | 가변저항 | 1 | 가변저항 |
7 | 푸시버튼 | 1 | 푸시버튼 |
8 | 리튬전지 | 1 | 3.7v |
9 | 리튬전지 충전모듈 | 1 | TP4056 |
10 | 10k 옴 저항 | 1 | 저항 |
11 | 270 옴 저항 | 3 | 저항 |
12 | 100 옴 저항 | 1 | 저항 |
13 | 전선 | 1 | 강선 |
14 | 인두기 | 1 | 인두 |
15 | 납 | 1 | 납 |
16 | 글루건 | 1 | 다용도 전동 공구 |
17 | 반구형 플라스틱 | 1 | 연질 플라스틱 |
18 | 가위 | 1 | 가위 |
19 | 칼 | 1 | 칼 |
20 | 부직포 | 1 | 부직포 |
부품명 | 아두이노 미니 | FTDI 232r USB | RGB LED | 피에조 부저 | 슬라이드 스위치 |
파트 | x1 | x1 | x1 | x1 | x1 |
부품명 | 가변저항 | 푸시버튼 | 리튬전지 | 리튬전지 충전모듈 | 10k 옴 저항 |
파트 | x1 | x1 | x1 | x1 | x1 |
부품명 | 270 옴 저항 | 100 옴 저항 | 전선 | 인두기 | 납 |
파트 | x1 | x1 | x1 | x1 | x1 |
부품명 | 글루건 | 반구형 플라스틱 | 가위 | 칼 | 부직포 |
파트 | x1 | x2 | x1 | x1 | x2 |
/************************************************* * Public Constants *************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
#include "pitches.h"
#define SONG1_SIZE 24
#define SONG2_SIZE 14
// notes in the melody 1:
int melody1[] = {
NOTE_D3, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_D3,
NOTE_D3, NOTE_D3, NOTE_D3, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_E3, 0,
NOTE_E3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_FS3, 0 ,
NOTE_D4, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_B3
};
// notes in the melody 2:
int melody2[] = {
NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C3, NOTE_AS3, NOTE_A3, NOTE_G3, NOTE_F3,
NOTE_C4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_F4
};
// note durations of melody 1: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations1[] = {
4, 4, 4, 4, 2.5,
8, 8, 4, 4, 4, 4, 2.5, 2,
4, 4, 4, 4, 2.5, 2,
4, 4, 4, 4, 1};
// note durations of melody 2: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations2[] = {
2, 2.5, 8, 1.5, 4, 2, 2 ,1.5,
4, 1.8, 4, 1.8, 4, 1};
//Pins
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int button = 2;
//control variables
int counter = 0;
int pressed = 0;
boolean playsong =false;
//song temp variables
int songSizeS;
int *noteDurationS = 0;
int *melodyS=0;
//speed control variables
int sensorValue = 0;
float tempo = 0;
// initialization
void setup() {
//setup pins
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(button, INPUT);
//light up to green at the beginning
mapColor(-1);
//debug purposes
Serial.begin( 9600 ); // optional
}
// main program
void loop() {
//detect when the button was pressed
if(digitalRead(button) ==LOW)
{
pressed = 1;
}
//detect when the button was realesed
if(digitalRead(button) ==HIGH && pressed == 1)
{
counter++;
pressed = 0;
playsong =true;//variable to control when to start the song
//decide which song plays
if( counter % 2 == 0 )
{
songSizeS = SONG1_SIZE;
noteDurationS = noteDurations1;
melodyS = melody1;
}
else
{
songSizeS = SONG2_SIZE;
noteDurationS = noteDurations2;
melodyS = melody2;
}
}
//start the song if the button was pressed:
if(playsong)
{
playsong =false;
// iterate over the notes of the melody
for (int thisNote = 0; thisNote < songSizeS ; thisNote++)
{
//sensor value from the potentiometer mapped to range of 1 - 3 speed values
sensorValue =analogRead(A0);
tempo = sensorValue * (3.0 / 1023.0); Serial.println(tempo);
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurationS[thisNote];
int noteDuration = 1000/noteDurationS[thisNote];
tone(8, melodyS[thisNote],noteDuration);
//light up the rgb-led depending of the note
mapColor( melodyS[thisNote] );
// to distinguish the notes, set a minimum time between them.
// the note's duration * tempo
int pauseBetweenNotes = noteDuration * tempo;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
//light up the led to initial state (green color)
mapColor(-1);
}
}
}
//function that maps the note to a certain color
// it combines the color of RGB to produce a different one
void mapColor(int note)
{
switch(note)
{
case NOTE_C3:
case NOTE_C4:
analogWrite(redPin, 0);
analogWrite(greenPin, 255 );
analogWrite(bluePin, 255);
break;
case NOTE_D3:
case NOTE_D4:
analogWrite(redPin, 0);
analogWrite(greenPin, 0 );
analogWrite(bluePin, 255);
break;
case NOTE_E3:
case NOTE_E4:
analogWrite(redPin, 255);
analogWrite(greenPin, 0 );
analogWrite(bluePin, 0);
break;
case NOTE_F3:
case NOTE_F4:
analogWrite(redPin, 0);
analogWrite(greenPin, 255 );
analogWrite(bluePin, 0);
break;
case NOTE_G3:
case NOTE_G4:
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
break;
case NOTE_A3:
case NOTE_A4:
analogWrite(redPin, 255);
analogWrite(greenPin, 255 );
analogWrite(bluePin, 0);
break;
case NOTE_B3:
case NOTE_B4:
analogWrite(redPin, 0);
analogWrite(greenPin, 0 );
analogWrite(bluePin, 0);
break;
case 0://it represents end state or silence
analogWrite(redPin, 255);
analogWrite(greenPin, 255 );
analogWrite(bluePin, 255);
break;
case -1:// it represents initial state
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
break;
default://other notes
analogWrite(redPin, 105);
analogWrite(greenPin, 255 );
analogWrite(bluePin, 100);
break;
}
}
hihyo