#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
#include <DallasTemperature.h>
#include <OneWire.h>
BlynkTimer timer;
SoftwareSerial mySerial1(A1, A0);
float dianYaZhi;
float wenDu;
OneWire oneWire_A2(A2);
DallasTemperature sensors_A2(&oneWire_A2);
DeviceAddress insideThermometer;
int delay_sj;
int dian_yuan;
int qi_dong;
char auth[] = "kCYIAdI1Yviy4f03hcM727qnvjhSXiqQ";//远程启动车的密钥
BLYNK_WRITE(V1) {//小车电源开关
dian_yuan = param[0].asInt();
if(dian_yuan){
digitalWrite(2,HIGH);
led1();
}else{
digitalWrite(2,LOW);
led1();
}
}
BLYNK_WRITE(V2) {//小车启动开关
qi_dong = param[0].asInt();
if(qi_dong){
digitalWrite(3,HIGH);
led1();
delay(delay_sj);
digitalWrite(3,LOW);
led1();
}
}
BLYNK_WRITE(V6) {//小车启动时间范围
delay_sj = param[0].asInt();
}
//-----------------向APP发送数值函数----------------
void myTimerEvent1() {//发送温度值
Blynk.virtualWrite(V4, wenDu);
}
void myTimerEvent2() {//发送电压值
Blynk.virtualWrite(V5, dianYaZhi);
}
BLYNK_WRITE(V7) {//灯带控制
int r = param[0].asInt();
int g = param[1].asInt();
int b = param[2].asInt();
}
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(A3,INPUT);
pinMode(A4,OUTPUT);//接《氛围灯》信号控制
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
sensors_A2.getAddress(insideThermometer, 0);
sensors_A2.setResolution(insideThermometer, 9);
Serial.begin(9600);
mySerial1.begin(9600);
Blynk.begin(mySerial1,auth);
timer.setInterval(1000L, myTimerEvent1);
timer.setInterval(1000L, myTimerEvent2);
}
void loop() {
// put your main code here, to run repeatedly:
wenDu = ds18b20_A2_getTemp(0) - 3;
DianYa();
Serial.println(wenDu);
Blynk.run();
timer.run();
}
//-------------------指示灯------------------
void led1(){
digitalWrite(LED_BUILTIN,HIGH);
delay(200);
digitalWrite(LED_BUILTIN,LOW);
delay(200);
}
//-------------------获取电压---------------------------
void DianYa(){//计算电压取值的函数
float temp;
dianYaZhi=analogRead(A3);
temp=dianYaZhi/48.6;
dianYaZhi=temp;
Serial.println(dianYaZhi);
delay(1000);
}
//----------------------获取温度-------------------
float ds18b20_A2_getTemp(int w) {
sensors_A2.requestTemperatures();
if(w==0) {
return sensors_A2.getTempC(insideThermometer);
}
else {
return sensors_A2.getTempF(insideThermometer);
}
}
72U4+Blynk远程遥控车启动
最新推荐文章于 2024-08-29 19:52:36 发布