BASIC4MCU | 질문게시판 | 답변 2: 아두이노 박수 카운트
페이지 정보
작성자 master 작성일2018-06-15 17:30 조회4,215회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=1898
본문
//#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 이상일 때if(count<6){ count++;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); }}}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=180; pos>=0; pos--){ EduServo.write(pos); delay(15); } // 180->0 회전if(count<6){ count++;digitalWrite(3,HIGH); for(int i=0; i<6; i++)digitalWrite(led[i],LOW); // OFF}}//delay(200); // 박수 중복 입력이 안되게 200ms 딜레이}}
댓글 0
조회수 4,215등록된 댓글이 없습니다.