BASIC4MCU | 질문게시판 | 아두이노 집안상황 모니터링 하는 작품인데 질문이요
페이지 정보
작성자 냉냉냥성냥 작성일2018-12-04 13:23 조회3,970회 댓글1건본문
저번에 고쳐 주신건데 loop문안에 room1이 있다보니 한번 돌때 room1값이 0으로 초기화가 되서 문을 열고 닫을수가 없네요. loop문이 끝나고 다시 돌때 room1값을 초기화시키지 않고 그대로 가지고 있으려면 어떻게 고쳐야 하나요?
#include <LED.h>
#include "Temperature.h"
#include "Humidity.h"
#include <UltraSonic.h>
#include "Switch.h"
#include "RgbLcd.h"
//
RgbLcd lcd;
LED myled;
Humidity humidity;
#define TEMP_ADDR 72
#define HUMI_ADC 55
UltraSonic dUltra;
Temperature temper;
Switch pushSwitch;
//
char* house[]={
" -------------------------------------------------------------------\r\n", //0
" | |\r\n", //1
" | veranda |\r\n", //2
" | |\r\n", //3
" -------------------------------------------------------------------\r\n", //4
" | | | |\r\n", //5
" | | | |\r\n", //6
" | | | |\r\n", //7
" | room 1 | | room 2 |\r\n", //8
" | | | |\r\n", //9
" | | | |\r\n", //10
"--------------------------- --------------\r\n", //11
"| | |\r\n", //12
"| t | living room |\r\n", //13
"| o | -------------|\r\n", //14
"| i | | |\r\n", //15
"| l | | |\r\n", //16
"| e | | room 3 |\r\n", //17
"| t | | |\r\n", //18
"| | | |\r\n", //19
"|----------------------------------------- ---------------------|\r\n", //20
" | | | |\r\n", //21
" | | | |\r\n", //22
" | door | | |\r\n", //23
" | | | |\r\n", //24
" |------------| | |\r\n", //25
" |------------| |\r\n", //26
" | |\r\n", //27
" | kitchen |\r\n", //28
" | |\r\n", //29
" | |\r\n", //30
" |------------------------|\r\n", //31
};
//
void tailPrint(){
Serial3.print("hudi: "); Serial3.print(humidity.read()); Serial3.println("%");
Serial3.print("temp: "); Serial3.print(temper.getTemperatureC()); Serial3.print("℃");
Serial3.print("\n\n");
}
//
void blueprint(){
for(int i=0; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_door_open(){
for(int i=0; i<24; i++)Serial3.print(house[i]);
Serial3.print(" | (light On) | | | \r\n"); //24
for(int i=25; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("light On\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_door_close(){
for(int i=0; i<24; i++)Serial3.print(house[i]);
Serial3.print(" | (light Off)| | | \r\n"); //24
for(int i=25; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("light Off\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_room1_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ --------------\r\n");
Serial3.print("| | | |\r\n");
Serial3.print("| t | | living room |\r\n");
for(int i=14; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_all_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ ------- |---\r\n");
Serial3.print("| | | | |\r\n");
Serial3.print("| t | living room | |\r\n");
Serial3.print("| o ------ ------| ---|\r\n");
Serial3.print("| i | |\r\n");
Serial3.print("| l | |\r\n");
for(int i=17; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_room1_2_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ ------ |----\r\n");
Serial3.print("| | | | |\r\n");
Serial3.print("| t | | living room |\r\n");
for(int i=14; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_room1_2_toilet_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ ------ |----\r\n");
Serial3.print("| | | | |\r\n");
Serial3.print("| t | | living room |\r\n");
Serial3.print("| o ------ -------------|\r\n");
Serial3.print("| i | |\r\n");
Serial3.print("| l | |\r\n");
for(int i=17; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_room1_toilet_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ --------------\r\n");
Serial3.print("| | | |\r\n");
Serial3.print("| t | | living room |\r\n");
Serial3.print("| o ------- -------------|\r\n");
Serial3.print("| i | |\r\n");
Serial3.print("| l | |\r\n");
for(int i=17; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void blueprint_room1_room3_open(){
for(int i=0; i<11; i++)Serial3.print(house[i]);
Serial3.print("----------| ------------ --------------\r\n");
Serial3.print("| | | |\r\n");
Serial3.print("| t | living room | |\r\n");
Serial3.print("| o | ----- |---|\r\n");
for(int i=15; i<32; i++)Serial3.print(house[i]);
tailPrint();
Serial3.print("\n\n\n\n\n\n\n\n\n\n\n\r\n");
}
//
void setup(){
humidity.begin(HUMI_ADC);temper.begin(TEMP_ADDR);
Serial3.begin(115200);
myled.begin(36);
dUltra.begin(75,2);
pushSwitch.begin();
lcd.begin(62,63,64,65,66,67,45,44,43,42,16,2);
lcd.onBacklightBlue();
Serial.begin(9600);
blueprint();
}//
void loop(){
int room1=0,room2=0,room3=0,toilet=0;
uint8_t pushKey=pushSwitch.getPushKey();
int distance=0;
distance=dUltra.ReadDistanceCentimeter();
delay(100);
//
if(distance<50){
myled.AllOn(); blueprint_door_open(); delay(3000);
myled.AllOff(); blueprint();
}
if(pushKey>0){
if(pushKey==1){if(room1==0){
if (room2==1&&room3==1&&toilet==1){ blueprint_all_open(); }else if(room2==1&&room3==0&&toilet==0){ blueprint_room1_2_open(); }
else if(room2==1&&room3==0&&toilet==1){ blueprint_room1_2_toilet_open(); }
else if(room2==0&&room3==1&&toilet==0){ blueprint_room1_room3_open(); }
else if(room2==0&&room3==0&&toilet==1){ blueprint_room1_toilet_open(); }
else if(room2==0&&room3==0&&toilet==0){ blueprint_room1_open(); }
else if(room2==1 && room3==1 && toilet==0){ }
else if(room2==0 && room3==1 && toilet==1){ }
room1=1;
}else if(room1==1){
if(room2==0&&room3==0&&toilet==0){ blueprint(); }
room1=0;
}}
else if(pushKey==2){ }
}}
댓글 1
조회수 3,970master님의 댓글
master 작성일
//
void loop(){
int room1=0,room2=0,room3=0,toilet=0;
이렇게 로컬변수로 선언 되어 있는데요
//
int room1=0,room2=0,room3=0,toilet=0;
//
void loop(){
함수 밖으로 빼면 전역변수가 됩니다.