BASIC4MCU | 질문게시판 | 답변 : 질문드립니다
페이지 정보
작성자 master 작성일2018-06-15 16:31 조회8,064회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=1892
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-06-15 오후 4:34:13// 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~13int soundSensor=A0; // 사운드 센서 핀//int sound=500; // 소리 크기 기준int pos=0;int count=0; // 박수를 몇 번 쳤는지 카운트//void setup(){Serial.begin(9600); // 시리얼모니터 출력pinMode(soundSensor,INPUT); // 사운드 센서 입력으로 설정pinMode(3,OUTPUT); // buzzerfor(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);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 회전}//delay(200); // 박수 중복 입력이 안되게 200ms 딜레이}}
else에 넣어주면 됩니다.
밖에 있을 때는 계속해서 서보모터가 돌았지만
안으로 이동하면 한번만 동작합니다.
댓글 0
조회수 8,064등록된 댓글이 없습니다.