답변 2: 아두이노 박수 카운트 서보모터 사운드
페이지 정보
작성자 master 작성일18-06-16 15:34 조회8,493회 댓글0건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-16 오후 3:37:43
// by Ok-Hyun Park
//
여기서 서보모터가 마지막에 계속 도는데 두번만 돌고
소리와 서보모터가 같이 멈추게 하려면 소스 어떻게 쳐야하나요?
//
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
#include <Servo.h>
Servo EduServo;
int led[6]={ 8,9,10,11,12,13}; // LED핀 8~13
int soundSensor=A0; // 사운드 센서 핀
int sound=500; // 소리 크기 기준
int pos=0;
int count=0; // sound count
//
void setup(){
Serial.begin(9600); // 시리얼모니터 출력
pinMode(soundSensor,INPUT); // 사운드 센서 입력으로 설정
pinMode(3,OUTPUT); // buzzer
for(int i=0; i<6; i++)pinMode(led[i],OUTPUT); // LED 핀 출력으로 설정
EduServo.attach(4);
lcd.init();
lcd.backlight();
}
//
void loop(){
digitalWrite(3,LOW);
if(analogRead(soundSensor)>=sound){ // 소리의 크기가 500 이상일 때
for(int i=0; i<6; i++){ // led 제어
if(i==count){ // 카운트 된 박수 개수로 led 제어
digitalWrite(led[i],HIGH);
lcd.setCursor(0,0); lcd.print("Turn on "); lcd.print(count);
}
else{ digitalWrite(led[i],LOW); digitalWrite(3,HIGH); }
}
if(count<6){ count++; }
else if(count<7){ count++;
lcd.setCursor(0,0); lcd.print("Turn off "); lcd.print(count);
for(pos=0; pos<=180; pos++){ EduServo.write(pos); delay(15); } // 0->180 회전
for(pos=0; pos<=180; pos++){ EduServo.write(pos); delay(15); } // 0->180 회전
digitalWrite(3,LOW);
}
delay(200);
}
}
댓글 : 0
조회수 : 8,493
등록된 댓글이 없습니다.