Created
July 2, 2016 04:41
-
-
Save taesamja/ad68ea2aa24b59cb2646223ada8dfb80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PI 3.141592 | |
#define piezoPin 12 //피에조 스피커 연결 핀 번호 | |
float sinVal; //정현파 값 저장 | |
int toneVal; //경보음 발생을 위한 값 저장 | |
void setup() | |
{ | |
pinMode(piezoPin, OUTPUT);//9번핀을 출력으로 설정 | |
} | |
void loop() | |
{ | |
for(int i=0;i<180;i++) | |
{ | |
sinVal=sin(i*PI/180); //각도를 라디언으로 바꿔 정현파 값 계산 | |
toneVal=(int)(100+1000*sinVal); //경보음 주파수(Hz)로 변환 | |
tone(piezoPin,toneVal);//피에조 스피커에서 주파수 발생 | |
delay(10); //경보음 주파수 변화 속도 조정 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment