//**********************************************//
//*************智能家居服务系统*****************//
//************2017.10.22************************//
#include <SoftwareSerial.h>
#include <EEPROM.h> //寄存器库
#include <Servo.h> //舵机库
//**********************//
int pos;
int a=22;//寄存器记忆开关按下状态
int value;//寄存器定义
int address=5;
int led=4;
int fan=5;
int music=6;
char val='/';
Servo myservo;
//*******************wait******************//
void setup()
{
EEPROM.write(address,a);
attachInterrupt(0, romote,RISING);
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
digitalWrite(2,LOW);
digitalWrite(5,HIGH);
myservo.attach(9);
myservo.write(pos);
delay(100);
myservo.detach();
}
//*************************do it***************//
void loop()
{
char c=Serial.read();
switch(c)
{
case('k'):dooropen();break;
case('g'):doorclose();break;
}
}
//************************************//
void romote()//外部中断
{
value = EEPROM.read(address);//寄存器记忆按钮状态
if(value==a)
{
digitalWrite(5,LOW);
EEPROM.write(address,11);
}
else
{
digitalWrite(5,HIGH);
EEPROM.write(address,22);
}
}
void ledopen()
{
digitalWrite(2,LOW);
}
void ledclose()
{
digitalWrite(2,HIGH);
}
void dooropen()
{
myservo.attach(9);
for(pos =60 ; pos <= 160; pos +=1)
{
myservo.write(pos);
delay(15);
}
bluetooth();
}
void doorclose()
{
myservo.attach(9);
for(pos =160 ; pos >= 60; pos -=1)
{
myservo.write(pos);
delay(15);
}
}
void bluetooth()//蓝牙反馈数据
{
Serial.println("Success");
}