BASIC4MCU | 질문게시판 | 아두이노 서보모터와 피에조부저 질문이요!ㅠ
페이지 정보
작성자 빵망이 작성일2018-12-06 18:36 조회6,848회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6457
본문
#include <Servo.h>
int analogPin = 0; // 워터센서 analog port 0 연결
int speakerPin = 9; // 피에조부저 연결 디지털핀
int val = 0; // 전류변화값
Servo myservo;
int pos = 0;
void setup ()
{
myservo.attach(8); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 90 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void loop()
{
val = analogRead(analogPin); // analogPin 의 변화값(전류값)을 읽음
if (val > 100) // val 값이 100이 넘으면 (전류가 100이 넘으면)
{
tone(speakerPin,1000, 5000); // 피에조 ON (주파수 1000으로 5초간 울리기)
delay(1000);
}
}
저희는 수위센서에 물이 닿으면 피에조부저가 울리는 동시에 서보모터가 계속 반복되지 않고 1번 만 같이 작동하는것을 하고싶은데 위의 코딩으로는 서보모터가 먼저 작동하고 수위센서에 물이 닿으면 소리가 울리는 동시에 서보모터 작동이 멈추네요... 위에 설명처럼 될려면 어떻게 코딩해야하나요?? 도와주시면 정말 감사하겠습니다ㅠㅠ
댓글 0
조회수 6,848등록된 댓글이 없습니다.