|
哪位大侠帮我看看,我东拼西凑的程序,手机上下了个blinker,设置了两个按钮,一个滑块,两个温湿度的显示窗口
现在开关按钮能控制外接arduion板的LED,滑块也能控制LED的亮度,但是外接的温湿度传感器一直没有数据显示,不知道是哪里的问题
#define BLINKER_BLE
#include <SHT1x.h>
#include <Blinker.h>
#define dataPin A1
#define clockPin A0
SHT1x sht1x(dataPin, clockPin);
BlinkerButton Button1("btn-led");
BlinkerSlider Slider1("sli-pwm");
BlinkerNumber TEMP("temp");
BlinkerNumber HUMI("humi");
float humi_read=20,temp_read=20;
int counter = 0;
uint32_t read_time = 0;
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if(state=="on"){
digitalWrite(13, HIGH);
analogWrite(5, 255);
Serial.println("开灯");}//串口打印
else if(state=="off"){
digitalWrite(13, LOW);
analogWrite(5, 0);
Serial.println("关灯");}
}
void slider1_callback(int32_t value)
{
BLINKER_LOG("get slider data: ", value);
analogWrite(5, value*255/100);
Serial.print("duty:");
Serial.print(value);
Serial.println("%");
}
void heartbeat()
{
TEMP.print(temp_read);
HUMI.print(humi_read);
}
void setup()
{
Serial.begin(9600);
BLINKER_DEBUG.stream(Serial);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Blinker.begin(2,3,9600);
Button1.attach(button1_callback);
Slider1.attach(slider1_callback);
Blinker.attachHeartbeat(heartbeat);
}
void loop()
{
Blinker.run();
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();
temp_read=sht1x.readTemperatureC();
humi_read=sht1x.readHumidity();
BLINKER_LOG("Humidity: ",h," %");
BLINKER_LOG("Temperature: ",t,"*C");
Blinker.print(temp_read,humi_read);
}
// Blinker.delay(1000);
}
|
-
|