blinker电源插座-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3281|回复: 5

[分享] blinker电源插座

[复制链接]
发表于 2020-1-10 06:41 | 显示全部楼层 |阅读模式
这台blinker电源插座有blinker控制和手动控制两种工作方式.
1.blinker控制:滑条用于设定时时间,数据块用于显示定时剩余时间,注意两者最大值应统一.两个开关按键一个用于起停定时控制,一个用于开关电源插座.
2.手动控制:插座上有三个按纽和一个LED显示器.一个按纽用于定时起停或开关电源(短按起或停长按开或关).另两个按纽为增减定时时间设定(最大值为999分)
  短按为慢调,长按为快调.
如有需求程序再上传.

572cc14c4daafe7dcd1c85043bce7658.jpg
dc4d937026583a7b4c925410fa6d97a9.jpg
发表于 2020-1-10 16:14 | 显示全部楼层
发下代码呗, 我想看下你按钮怎么去抖的
发表于 2020-1-10 16:15 | 显示全部楼层
另外有没有硬件组装过程图呀?比较好奇你用了什么继电器, 怎么塞进去的,嘿嘿
 楼主| 发表于 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--;

}
}


b8a7e3b1eb7b19952b481f75e93e3d6c.jpg
发表于 2020-1-14 21:01 | 显示全部楼层
厉害,膜拜中
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 05:46 , Processed in 0.215954 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表