BASIC4MCU | 질문게시판 | 답변 : 아두이노 슬레이브 코드 질문 합니다.
페이지 정보
작성자 master 작성일2019-05-27 15:18 조회5,986회 댓글2건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=8858
작성일
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2019-05-27 오후 3:24:35// by Ok-Hyun Park//제가 일정수치 이상의 근전도 수치를 받으면 소리가 꺼지게 하고 싶은데while(free); 이 부분을disital.write(8,LOW)noTone(8)로 바꿔봣는데 스피커가 안꺼져서loop가 완전 끝나는 코드를 넣엇습니다.그랫더니 LCD의 현재시간 또한 꺼지는데혹시 어떻게 해야 스피커만 꺼지게 할 수 있는지 알 수 있을까요?ㅠㅠㅠㅠ////<슬레이브코드>#include <LiquidCrystal.h>LiquidCrystal lcd(12,11,5,4,3,2); //RS 핀,E핀,데이터 핀 4개//#include "pitches.h"int melody[]={NOTE_C4,NOTE_G3,NOTE_G3,NOTE_A3,NOTE_G3,0,NOTE_B3,NOTE_C4};int noteDurations[]={4,8,8,4,4,4,4,4};//#include <swRTC.h>swRTC rtc;//#include <SoftwareSerial.h>SoftwareSerial mySerial(9,10); //블루투스의 Tx,Rx핀을 2번 3번핀으로 설정//int piezo=8,switchPin=9;//char incomingByte; // 수신 데이터를 저장하는 변수String lcdString=""; // 객체 선언: 출력 할 글자 저장int counter=0,temp;//void Set_AMPM(int hour){ //AM PM을 구분해 주는 함수if(hour>=12)lcd.print("PM"); else lcd.print("AM");lcd.print(hour%12,DEC);}//void Set_lowThanTen(int time){ if(time<10)lcd.print("0"); lcd.print(time); } //10보다 작은수를 출력할때 앞에 0을 출력하게 하는 함수//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()){for(int thisNote=0; thisNote<8; thisNote++){int noteDuration=1000/noteDurations[thisNote];tone(8,melody[thisNote],noteDuration);int pauseBetweenNotes=noteDuration*1.30;delay(pauseBetweenNotes);noTone(8);}}}//void setup(){pinMode(8,OUTPUT); pinMode(piezo,OUTPUT); pinMode(switchPin,INPUT_PULLUP);lcd.begin(16,2); lcd.clear();rtc.stopRTC(); rtc.setTime(10,05,30); rtc.setDate(27,5,2019); rtc.startRTC();Serial.begin(9600); while(!Serial){} Serial.println("Hello World!");mySerial.begin(9600); //블루투스}//void loop(){char theDay[4]; int i=0,day; int stop=0;//lcd.setCursor(0,0); Set_AMPM(rtc.getHours()); //1초 단위로 갱신하며 현재시간을 LCD에 출력lcd.print(": "); Set_lowThanTen(rtc.getMinutes());lcd.print(": "); Set_lowThanTen(rtc.getSeconds());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(": "); //세팅된 알람시간을 LCD에 출력Set_lowThanTen(0006%100);lcdString=""; lcd.print(" "); delay(1000); //1초마다 LCD갱신 //문자열 초기화 //전 글씨 삭제if(stop==0)checkTheAlarmTime(temp/100,temp%100); //알람이 울릴 시간인지 체크//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);}//스위치버튼이 눌렸을 경우 피에조센서의 소리를 0으로 하고 알람시간을 초기화 한다if(mySerial.available()){ //블루투스에서 넘어온 데이터가 있다면incomingByte=mySerial.read(); //날라온 데이터를 읽기Serial.print(incomingByte);//날라온 데이터를 읽기if(incomingByte=='1')counter++;if(counter==4){ stop=1; }}}//
댓글 2
조회수 5,986쥬스님의 댓글
쥬스 작성일이 코드 복사해서 해봤는데 그래도 스피커가 안꺼져요ㅜㅠ ‘1’이 4번 왔는데도 안꺼져요ㅜㅠㅠㅠ 왜그런걸까요ㅜㅠㅠㅠ
master님의 댓글
master
void loop(){
char theDay[4]; int i=0,day;
int stop=0; // <--- 여기서 0을 주면 계속 0이 됩니다.
//--------------------------------------------
int stop=0; // <--- 전역변수 위치로 옮기세요
//
void loop(){
char theDay[4]; int i=0,day;