BASIC4MCU | 질문게시판 | 답변 : 아두이노 박수 카운트 서보모터 사운드
페이지 정보
작성자 master 작성일2018-06-16 15:33 조회8,267회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=1921
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-06-16 오후 3:36:44// 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; // sound count//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 if(count<8){ 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 회전}else{ digitalWrite(3,LOW); } // count=8delay(200);}}
댓글 0
조회수 8,267등록된 댓글이 없습니다.