BASIC4MCU | 질문게시판 | 아두이노 알람시계 질문합니다!!
페이지 정보
작성자 쥬스 작성일2019-05-25 10:02 조회10,770회 댓글3건본문
/*
LCD 연결해서 글자 출력하기
이 스케치는 KocoaFab에서 만들었습니다.
이 스케치는 누구든 무료로 사용할 수 있습니다.
*/#include <LiquidCrystal.h>
#include <swRTC.h>LiquidCrystal lcd(12,11,5,4,3,2); //RS 핀, E핀, 데이터 핀 4개
String lcdString = ""; //객체 선언 : 출력 할 글자 저장swRTC rtc;
int piezo = 8;
int switchPin = 9;
int temp;//AM PM을 구분해 주는 함수
void Set_AMPM(int hour) {
if(hour >=12)
lcd.print("PM");
else
lcd.print("AM");lcd.print(hour%12, DEC); //시간 출력
}//10보다 작은수를 출력할때 앞에 0을 출력하게 하는 함수
void Set_lowThanTen(int time) {
if(time < 10) {
lcd.print("0");
lcd.print(time%10);
}
else
lcd.print(time);
}//유효한 알람시간인지 체크하는 함수
int checkTheAlarmClock(int time) {
if(time/100 < 24 && time %100 < 60) {
Serial.println("Success");
return time;
}
else {
Serial.println("Failed");
return 0;
}
}//알람이 울릴시간인지 체크하는 함수
void checkTheAlarmTime(int alarmHour, int alarmMinute) {
if(alarmHour == rtc.getHours() && alarmMinute == rtc.getMinutes()) {
analogWrite(piezo, 255);
}
}void setup() {
lcd.begin(16,2); //LCD 크기 지정, 2줄 16칸
lcd.clear(); //화면 초기화
rtc.stopRTC(); //정지
rtc.setTime(10,05,0); //시간, 분, 초 초기화
rtc.setDate(25, 5, 2019); //일, 월, 년 초기화
rtc.startRTC(); //시작
pinMode(piezo, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
Serial.begin(9600); //시리얼 포트 초기화
Serial.begin(9600); //시리얼 통신 초기화
}void loop() {
int day;
lcd.setCursor(0,0); //커서를 0,0에 지정
//1초 단위로 갱신하며 현재시간을 LCD에 출력
Set_AMPM(rtc.getHours());
lcd.print(":");
Set_lowThanTen(rtc.getMinutes());
lcd.print(":");
Set_lowThanTen(rtc.getSeconds());
//날짜를 LCD에 출력
lcd.print("[");
Set_lowThanTen(rtc.getMonth());
lcd.print("/");
Set_lowThanTen(rtc.getDay());
lcd.print("]");
//세팅된 알람시간을 LCD에 출력
lcd.setCursor(0,1);
lcd.print("Alarm ");
Set_AMPM(1000/100);
lcd.print(":");
Set_lowThanTen(0006%100);
//1초마다 LCD갱신
lcdString = ""; //문자열 초기화
lcd.print(" "); //전 글씨 삭제
delay(1000);
//알람이 울릴 시간인지 체크
checkTheAlarmTime(temp/100, temp%100);
//스위치버튼이 눌렸을 경우 피에조센서의 소리를 0으로 하고 알람시간을 초기화 한다
if(!digitalRead(switchPin)) {
temp = 0;
day = 0;
analogWrite(piezo, 0);
Serial.println("Alarm clock initialize");
Serial.println("AM0:00");
}
//시리얼 통신을 통해 알람시간을 입력받고 시리얼 모니터에 출력
char theDay[4];
int i = 0;
if(Serial.available()) {
while(Serial.available()) {
theDay[i] = Serial.read();
i++;
}
day = atoi(theDay);
if(day/100 >= 12) {
Serial.print("PM");
Serial.print((day/100)-12);
}
else {
Serial.print("AM");
Serial.print(day/100);
}
Serial.print(":");
if(day%100 < 10)
Serial.print("0");
Serial.println(day%100);
temp = checkTheAlarmClock(day);
}
}
여기서 피에조 부저 대신 아두이노 스피커로 연결하려면 코딩을 어떻게 바꿔야할까요??ㅠㅠ
댓글 3
조회수 10,770master님의 댓글
master 작성일
아두이노 스피커라는 것이 어떤 것을 말할까요?
판매사이트 링크를 올려보세요
쥬스님의 댓글
쥬스 작성일master님의 댓글
master
https://www.arduino.cc/en/Tutorial/ToneMelody?from=Tutorial.Tone
이 예제를 공부해서 만들어보세요