Install arduino
#define BLINKER_WIFI #define BLINKER_MIOT_LIGHT #include <Blinker.h> #include <Servo.h> Servo myservo;//Define the steering gear char auth[] = "xxxxx"; // Lighting Key char ssid[] = "xxxx"; // Wifi name char pswd[] = "12345678"; // Wifi password //New Component Object BlinkerButton Button1("test"); int counter = 0; Void miotPowerState (const String&state)//Power class operations { BLINKER_LOG("need set power state: ", state); if (state == BLINKER_CMD_ON) { myservo.write(0);// The steering gear rotates 110 degrees after receiving the "on" command BlinkerMIOT.powerState("on"); BlinkerMIOT.print();// Feedback status delay(500);// Delay 0.5 s myservo.write(0);// The steering gear returns to zero and vertical state } else if (state == BLINKER_CMD_OFF) { myservo.write(0); // Steering gear deflection 70 ° BlinkerMIOT.powerState("off"); BlinkerMIOT.print(); delay(500); myservo.write(0); } } //Press the key to execute the function and change the steering gear rotation to the following void button1_callback(const String & state) { BLINKER_LOG("get button state: ", state); if (state=="on") { myservo.write(180);// After receiving the "on" command, the steering gear rotates 150, counterclockwise delay(500);// delayed myservo.write(90);// Steering gear zeroed and vertical } else if(state=="press"||state=="tap") { myservo.write(-180);// After long pressing the switch button, the steering gear rotates 30, clockwise delay(500);// delayed myservo.write(90);// Steering gear zeroed and vertical } } //If an unbound component is triggered, its contents will be executed void dataRead(const String & data) { BLINKER_LOG("Blinker readString: ", data); counter++; } void setup() { //Initialize serial port Serial.begin(115200); BLINKER_DEBUG.stream(Serial); //Initialize the steering gear myservo.attach(2);// I/O port of steering gear, D4 port of nodemcu myservo.write(90);// When power on, the steering gear returns to zero and vertical BlinkerMIOT.attachPowerState(miotPowerState); //Initialize blinker Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Button1.attach(button1_callback); } void loop() { Blinker.run(); }
{config → headerColor → transparent → headerStyle → dark → background → img → assets/img/headerbg.jpg → isFull → dashboard → | {type → btn → ico → fad fa lightbulb on → mode → t0 → turn on the light t1 Text 2 {ß A ß B ß C ß E ß E ß F ß H ß I ß J Ì K ß L Í M ß N ß x Ë y ß O | ÷ R ß S ß {T} ß A ¨ deb ¨ E E E E E E E K ∨ L ß M ¨ debug ¨ x ´´ y ´´ D} ÷ actions ¨ | ε cmd ¨ switch ¨ ‡¨ text ¨ ‡ Q ¨ Open? Name ¨ off ¨ Close? Name ¨ ÷ ¨ triggers ¨ | {¨ source ¨ a ¨ source_zh ¨ Switch status ¨ state ¨ | ß Q ¨ d ÷ ¨ state_zh ¨ | ¨ Open ¨ Close ¨ ÷} ÷}