学科竞赛作品整理
第二次修改代码,完美运行。但是这不是重点,重点还是安卓程序。马上开战,今天搞定!
//**********************************************// //*************智能家居服务系统*****************// //************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); digitalWrite(6,LOW); 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; case('l'):ledopen();break; case('m'):ledclose();break; case('f'):fanopen();break; case('o'):fanclose();break; } } //************************************// void romote()//外部中断 { value = EEPROM.read(address);//寄存器记忆按钮状态 Serial.println(value); if(value==a) { digitalWrite(5,LOW); EEPROM.write(address,11); } else { digitalWrite(5,HIGH); EEPROM.write(address,22); } } void fanopen() { digitalWrite(6,HIGH); Serial.println("fanopen!"); } void fanclose() { digitalWrite(6,LOW); Serial.println("fanclose!"); } void ledopen() { digitalWrite(5,LOW); Serial.println("ledopen!"); } void ledclose() { digitalWrite(5,HIGH); Serial.println("ledclose!"); } void dooropen() { myservo.attach(9); for(pos =60 ; pos <= 180; pos +=1) { myservo.write(pos); delay(15); } Serial.println("Success"); } void doorclose() { myservo.attach(9); for(pos =180 ; pos >= 60; pos -=1) { myservo.write(pos); delay(15); } Serial.println("defeat"); } void bluetooth()//蓝牙反馈数据 { Serial.println("Success"); }
@青山不移,文笔不息。学习,坚持,梦想青春!