哪位大神有esp-1s的两路继电器控制代码拿来分享分享呗-Arduino中文社区 - Powered by Discuz! Archiver

ebeeb 发表于 2021-3-10 08:22

myself1820 发表于 2021-3-5 17:26
能否发我一份,谢谢

在家里电脑上,等我回去传上来,

myself1820 发表于 2021-3-10 11:31

ebeeb 发表于 2021-3-10 08:22
在家里电脑上,等我回去传上来,

:handshake非常感谢

ebeeb 发表于 2021-3-11 19:37

本帖最后由 ebeeb 于 2021-3-11 19:40 编辑

myself1820 发表于 2021-3-10 11:31
非常感谢
//天空之城 最后编辑时间2020-12-20,TX变为GPIO1,RX变为GPIO3,
#define BLINKER_WIFI
#include <Blinker.h>

#define OUT1 0
#define OUT2 1
#define OUT3 2
#define OUT4 3

char auth[] = "**";//秘钥
char ssid[] = "**";      //wifi账号
char pswd[] = "**";   //wifi密码

BlinkerButton Button1("OUT1");//开关按键
BlinkerButton Button2("OUT2");//开关按键
BlinkerButton Button3("OUT3");//开关按键
BlinkerButton Button4("OUT4");//开关按键
BlinkerButton Button5("ON");//全开 普通按键
BlinkerButton Button6("OFF");//全关 普通按键

BlinkerNumber Number1("WiFi");
void button1_callback(const String & state)
{
    if(state == BLINKER_CMD_ON)
    {
      digitalWrite(OUT1,HIGH);
      Button1.print("on");
    }
    else if(state == BLINKER_CMD_OFF)
    {   
      digitalWrite(OUT1,LOW);
      Button1.print("off");
    }
   
}


void button2_callback(const String & state)
{
   
    if(state == BLINKER_CMD_ON)
    {
      digitalWrite(OUT2,HIGH);
      Button2.print("on");
    }
    else if(state == BLINKER_CMD_OFF)
    {   
      digitalWrite(OUT2,LOW);
      Button2.print("off");
    }
}

void button3_callback(const String & state)
{
   
    if(state == BLINKER_CMD_ON)
{
    digitalWrite(OUT3,HIGH);
    Button3.print("on");
}
else if(state == BLINKER_CMD_OFF)
{   
    digitalWrite(OUT3,LOW);
    Button3.print("off");
}
}

void button4_callback(const String & state)
{
   
    if(state == BLINKER_CMD_ON)
{
    digitalWrite(OUT4,HIGH);
    Button4.print("on");
}
else if(state == BLINKER_CMD_OFF)
{   
    digitalWrite(OUT4,LOW);
    Button4.print("off");
}
}


void button5_callback(const String & state)
{
   
if(state == BLINKER_CMD_BUTTON_TAP)
{
    digitalWrite(OUT1,HIGH);
    digitalWrite(OUT2,HIGH);
    digitalWrite(OUT3,HIGH);
    digitalWrite(OUT4,HIGH);
    Button1.print("on");
    Button2.print("on");
    Button3.print("on");
    Button4.print("on");
}
}


void button6_callback(const String & state)
{
   
if(state == BLINKER_CMD_BUTTON_TAP)
{
    digitalWrite(OUT1,LOW);
    digitalWrite(OUT2,LOW);
    digitalWrite(OUT3,LOW);
    digitalWrite(OUT4,LOW);
    Button1.print("off");
    Button2.print("off");
    Button3.print("off");
    Button4.print("off");
}
}

void heartbeat()
{
    if(digitalRead(OUT1)==1)//1
    {
   Button1.print("on");
    }
    else
    {
      Button1.print("off");
    }

    if(digitalRead(OUT2)==1)//2
    {
   Button2.print("on");
    }
    else
    {
      Button2.print("off");
    }

    if(digitalRead(OUT3)==1)//3
    {
   Button3.print("on");
    }
    else
    {
      Button3.print("off");
    }

    if(digitalRead(OUT4)==1)//4
    {
   Button4.print("on");
    }
    else
    {
      Button4.print("off");
    }

    Number1.print((uint8_t)WiFi.RSSI());
}

void setup()
{
pinMode(OUT1,OUTPUT);
digitalWrite(OUT1,LOW);
pinMode(OUT2,OUTPUT);
digitalWrite(OUT2,LOW);
pinMode(OUT3,OUTPUT);
digitalWrite(OUT3,LOW);
pinMode(OUT4,OUTPUT);
digitalWrite(OUT4,LOW);

//Serial.begin(115200);
//BLINKER_DEBUG.stream(Serial);
Blinker.begin(auth, ssid, pswd);

Blinker.attachHeartbeat(heartbeat);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
}

void loop()
{
    Blinker.run();
}

ebeeb 发表于 2021-3-11 19:39

本帖最后由 ebeeb 于 2021-3-11 19:42 编辑

myself1820 发表于 2021-3-10 11:31
非常感谢
{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨btn¨¨ico¨¨fal fa-power-off¨¨mode¨Ê¨t0¨¨开关1¨¨t1¨¨文本2¨¨bg¨É¨cols¨Ë¨rows¨Ë¨key¨¨OUT1¨´x´Ê´y´Ï¨speech¨|÷¨lstyle¨Ê¨clr¨¨#00A90C¨}{ßAßBßCßDßEÊßF¨开关2¨ßHßIßJÉßKËßLËßM¨OUT2¨´x´Î´y´ÏßO|÷ßPÊßQßR}{ßAßBßCßDßEÊßF¨开关4¨ßHßIßJÉßKËßLËßM¨OUT4¨´x´Î´y´ÒßO|÷ßPÊßQßR}{ßAßBßCßDßEÊßF¨开关3¨ßHßIßJÉßKËßLËßM¨OUT3¨´x´Ê´y´ÒßO|÷ßPÊßQßR}{ßAßBßCßDßEÉßF¨全开¨ßHßIßJÉßKÍßLÍßM¨ON¨´x´É´y´¤CßO|÷ßPËßQßR}{ßAßBßCßDßEÉßF¨全关¨ßHßIßJÉßKÍßLÍßM¨OFF¨´x´Í´y´¤CßO|÷ßPËßQ¨#EA0909¨}{ßA¨num¨ßF¨信号¨ßC¨fad fa-signal¨ßQ¨#389BEE¨¨min¨É¨max¨¢1c¨uni¨¨db¨ßJÉßKÍßLËßM¨WiFi¨´x´É´y´ÌßO|÷ßPÊ}÷¨actions¨|÷¨triggers¨|÷}

myself1820 发表于 2021-3-12 08:54

ebeeb 发表于 2021-3-11 19:39
{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img ...

谢谢楼主:handshake
页: 1 [2]
查看完整版本: 哪位大神有esp-1s的两路继电器控制代码拿来分享分享呗