我的博客日記
阿新 • • 發佈:2017-10-24
dcl mod 藍牙 digi detach attach print else inter
//**********************************************//
//*************智能家居服務系統*****************//
//************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");
}
我的博客日記