|
楼主 |
发表于 2020-1-10 18:03
|
显示全部楼层
本帖最后由 lwq1947 于 2020-1-10 18:05 编辑
由于空间有限所以电源控制采用了双向可控硅元件.组装过程没拍照.上传一张最终图片.程序如下:
#define BLINKER_WIFI
#include <Blinker.h>
#include <Arduino.h>
#include <Ticker.h>
#include <TM1637Display.h>
#define CLK 3
#define DIO 1
TM1637Display display(CLK, DIO);
Ticker flipper;
char auth[] = "**********";
char ssid[] ="**********";
char pswd[] = "*********";
#define BUTTON_1 "ButtonKey"
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button("star");
#define Slider_1 "SliderKey"
BlinkerSlider Slider1(Slider_1);
BlinkerNumber Tval("tval");
int t;
int i=0;
int j=0;
int k=0;
int l=0;
uint32_t BlinkerTime;
uint32_t pTime=0;
uint32_t dTime=0;
float tval_read=1;
void flip() {
if(digitalRead(2)==LOW) i=0;
if(digitalRead(2)==HIGH){
i++;
if((i>59)&&(t>0)){
i=0;
t--;
Tval.print(tval_read);
tval_read = t;
Tval.print(tval_read);
tval_read = t;
if(t==0)digitalWrite(2, LOW);
}
}
}
void button_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP) {
BLINKER_LOG("Button tap!");
digitalWrite(2, !digitalRead(2));
if(digitalRead(2)==HIGH)
{Button.icon("fas fa-lightbulb fa-spin");
Button.color("#FF0000");
Button.text("启动");
i=0;
j=0;}
else
{ Button.icon("fal fa-lightbulb ");
Button.color("#0000FF");
Button.text("停止");
}
Button.print();
}
}
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="on")
{
Button1.icon("fas fa-sun fa-spin");//fa-lightbulb
Button1.color("#FF0000");
Button1.text("开");
digitalWrite(15, HIGH);
Button1.print("on");
}
else if(state=="off")
{
Button1.icon("fal fa-moon");
Button1.color("#0000FF");
Button1.text("关");
digitalWrite(15, LOW);
digitalWrite(2, LOW);
Button1.print("off");
}
}
void slider1_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
t=value;
Tval.print(tval_read);
tval_read = t;
t=value;
Tval.print(tval_read);
tval_read = t;
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{ Tval.print(tval_read);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
flipper.attach(1, flip);
pinMode(0,INPUT);
pinMode(12,INPUT);
pinMode(16,INPUT);
pinMode(15,OUTPUT);
pinMode(2,OUTPUT);
digitalWrite(0,HIGH);
digitalWrite(12,HIGH);
digitalWrite(16,HIGH);
digitalWrite(15,LOW);
digitalWrite(2, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button.attach(button_callback);
Slider1.attach(slider1_callback);
}
void loop()
{
Blinker.run();
tval_read = t;
display.setBrightness(0x04);
display.showNumberDec(t, false);
delay(10);
BlinkerTime = millis();
if ( BlinkerTime - pTime > 50) {
j++;
pTime= BlinkerTime;}
if((k==0)&&((digitalRead(16)==LOW)||(digitalRead(12)==LOW)||(digitalRead(0)==LOW))){
k=1;
dTime= BlinkerTime;
if(digitalRead(0)==LOW) digitalWrite(2, !digitalRead(2));
}
if((digitalRead(16)==HIGH)&&(digitalRead(12)==HIGH)&&(digitalRead(0)==HIGH)){
k=0;
l=0;
}
if(( BlinkerTime - dTime > 3000)&&(digitalRead(16)==LOW))t++;
if(( BlinkerTime - dTime > 3000)&&(digitalRead(12)==LOW)&&(t>0))t--;
if(( BlinkerTime - dTime > 3000)&&(digitalRead(0)==LOW)&&(l==0)){
digitalWrite(15, !digitalRead(15));
if(digitalRead(15)==LOW)digitalWrite(2, LOW);
l=1;
}
if(j>9)
{
j=0;
if(digitalRead(16)==LOW)t++;
if((digitalRead(12)==LOW)&&(t>0))t--;
}
}
|
-
|