질문드립니다
페이지 정보
작성자 궁징 작성일18-06-15 15:59 조회7,279회 댓글0건본문
#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; // 박수를 몇 번 쳤는지 카운트
//
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 { lcd.setCursor(0,0); lcd.print("Turn off "); lcd.print(count); }
//
delay(200); // 박수 중복 입력이 안되게 200ms 딜레이
}
if(count>6){
for(pos=0;pos<=180;pos++){ EduServo.write(pos); delay(15); } // 0->180 회전
for(pos=180;pos>=0;pos--){ EduServo.write(pos); delay(15); } // 180->0 회전
}
}
if(count<6){ count++; }
else { lcd.setCursor(0,0); lcd.print("Turn off "); lcd.print(count); }
박수치면 led 6개가 하나씩 켜지고 꺼지고 하는데 6개 다켜지고 7번치면 lcd판에 turn off가 나옵니다 turn off 뜨면서 같이 서보모터 까지 돌리고 싶은데 어떻게 해야할까요 부탁드리겠습니다.
댓글 : 0
조회수 : 7,279
등록된 댓글이 없습니다.