- UID
- 806464
- 阅读权限
- 15
- 推广
-
- 幽默
-
- 注册时间
- 2015-8-19
- 最后登录
- 1970-1-1
|
注册家电维修技术论坛,与同行畅聊维修技术,享更多技术论坛功能。
您需要 登录 才可以下载或查看,没有帐号?快速注册
x
本帖最后由 cf小张 于 2020-6-1 09:34 编辑
经过将近几个月的稳定试验决定发出来(不要轻易模仿有一定的危险性)可通过点灯app远程启动汽车,锁车门,开车门,以及检测车内温度湿度,升窗,降窗,锁车门自动升窗。所有代码都是用arduino写的!具体细节vx:cfzjy1996
共使用了7个端口,还有一个端口D8预留
D0上锁
D1开锁
D2温度湿度回传
D3升车窗
D4降车窗
D5电源开关
D6广告开关
D7点火启动
D8预留
远程点火
手机控制
代码如下
#define BLINKER_WIFI
#include <Blinker.h>
#include <DHT.h>
BlinkerButton Button1("锁门");//数据键名
BlinkerButton Button2("开门");
BlinkerButton Button3("升窗");
BlinkerButton Button4("降窗");
BlinkerButton Button5("电源");
BlinkerButton Button6("广告");
BlinkerButton Button7("启动");
BlinkerButton Button8("预留");
char i;
char auth[] = "--------"; //设备码
char ssid[] = "--------"; //WiFi名称
char pswd[] = "--------"; //WiFi密码
BlinkerNumber TEMP("温度"); //温度数据键名
BlinkerNumber HUMI("湿度"); //湿度数据键名
#define DHTPIN D2 //定义DHT11模块连接管脚D2
#define DHTTYPE DHT11 //使用DHT11温度湿度模块
DHT dht(DHTPIN, DHTTYPE); //定义dht
float humi_read = 0, temp_read = 0;
void heartbeat() //数据同步
{
BLINKER_LOG("状态同步!");
if(digitalRead(D5)==HIGH)
{
Button7.print("off");
Button7.color("#0066FF");//颜色
Button7.text("熄火");
}
else
{
Button7.print("on");
Button7.color("#FF0000");//颜色
Button7.text("启动");
TEMP.print(temp_read);
HUMI.print(humi_read);
}
}
void button1_callback(const String & state) //锁门//升窗
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D0, HIGH);
Blinker.delay(200);
digitalWrite(D0, LOW);
digitalWrite(D3, HIGH);
Blinker.delay(4500);
digitalWrite(D3, LOW);
}
void button2_callback(const String & state) //开门
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D1, HIGH);
Blinker.delay(200);
digitalWrite(D1, LOW);
}
void button3_callback(const String & state) //升窗
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D3, HIGH);
Blinker.delay(1000);
digitalWrite(D3, LOW);
}
void button4_callback(const String & state) //降窗
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D4, HIGH);
Blinker.delay(500);
digitalWrite(D4, LOW);
}
void button5_callback(const String & state) //电源
{
if (digitalRead(D5) == HIGH) {
BLINKER_LOG("断电");
digitalWrite(D5, LOW);
Button5.color("#999999");//颜色
Button5.print("off");
}
else if (digitalRead(D5) == LOW) {
BLINKER_LOG("通电");
digitalWrite(D5, HIGH);
Button5.color("#66CC00");//颜色
Button5.print("on");
}
}
void button6_callback(const String & state) //广告
{
if (digitalRead(D6) == HIGH){
BLINKER_LOG("广告关");
digitalWrite(D6, LOW);
Button6.color("#999999"); //颜色
Button6.print("off");
}
else if (digitalRead(D6) == LOW){
BLINKER_LOG("广告开");
digitalWrite(D6, HIGH);
Button6.color("#fddb00");//颜色
Button6.print("on");
}
}
void button7_callback(const String & state) //启动//熄火
{
if (digitalRead(D5) == HIGH){
BLINKER_LOG("熄火");
Button7.color("#FF0000"); //颜色
Button7.text("启动");
Button7.print("off");
digitalWrite(D5, LOW);
digitalWrite(D6, LOW);
}
else if (digitalRead(D5) == LOW){
BLINKER_LOG("启动");
Button7.color("#0066FF"); //颜色
Button7.text("熄火");
Button7.print("on");
digitalWrite(D1, HIGH);
Blinker.delay(200);
digitalWrite(D1, LOW);
digitalWrite(D5,HIGH);
digitalWrite(D7, HIGH);
Blinker.delay(700);
digitalWrite(D7, LOW);
digitalWrite(D6, HIGH);
}
}
void button8_callback(const String & state) //预留
{
if (digitalRead(D8) == LOW){
BLINKER_LOG("关");
digitalWrite(D8, LOW);
Button8.color("#0066FF"); //颜色
Button8.print("off");
}
else if (digitalRead(D8) == HIGH){
BLINKER_LOG("开");
digitalWrite(D8, HIGH);
Button8.color("#FF0000"); //颜色
Button8.print("on");
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
dht.begin();
pinMode(D0, OUTPUT);
digitalWrite(D0, LOW);
pinMode(D1, OUTPUT);
digitalWrite(D1,LOW);
pinMode(D3, OUTPUT);
digitalWrite(D3,LOW);
pinMode(D4, OUTPUT);
digitalWrite(D4,LOW);
pinMode(D5, OUTPUT);
digitalWrite(D5,LOW);
pinMode(D6, OUTPUT);
digitalWrite(D6,LOW);
pinMode(D7, OUTPUT);
digitalWrite(D7,LOW);
pinMode(D8, OUTPUT);
digitalWrite(D8,LOW);
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Blinker.attachHeartbeat(heartbeat);
}
void loop()
{
Blinker.run();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
}
Blinker.delay(2000);
}
|
-
车窗升降
|