The actual code:
#include
//define the serial number and the function
# define Dong1 D6
# define Dong2 D7
# define Zhuan1 D4
# define Zhuan2 D5
# define Echo D2
# define Trig D8
Char * ssid="iPhone";
char *password="1024575686";
Int port=8888;//port
WiFiServer server(port);//set the port number
Long getTime () {//get back and forth time
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
DigitalWrite (Trig, LOW);
return pulseIn(Echo, HIGH);
}
Void initChaoShengBo () {//initializes the ultrasonic
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
}
Void initWiFiSta () {//initializes the WIFI module
WiFi. Mode (WIFI_STA);//set the STA model
WiFi. The begin (ssid, password);
While (WiFi. The status ().={WL_CONNECTED)
Serial. Print (", ");
Delay (500);
}
Serial. Println (WiFi. LocalIP ()); The IP address of the//print via a serial port wemos
}
Void initL9110S () {//initialization module 911 make for the output
PinMode (Dong1, the OUTPUT);
PinMode (Dong2, the OUTPUT);
PinMode (Zhuan1, the OUTPUT);
PinMode (Zhuan2, the OUTPUT);
}
Controlled by the rear wheel before and after the//
Void hou () {
DigitalWrite (Dong1, HIGH);
DigitalWrite (Dong2, LOW);
}
Void qian () {
DigitalWrite (Dong1, LOW);
DigitalWrite (Dong2, HIGH);
}
//controlled by the front wheels
Void zuo () {
DigitalWrite (Zhuan1, HIGH);
DigitalWrite (Zhuan2, LOW);
}
Void you () {
DigitalWrite (Zhuan2, HIGH);
DigitalWrite (Zhuan1, LOW);
}
Void setup () {
//put your setup code here, to run once:
InitL9110S ();
InitChaoShengBo ();
Serial. The begin (115200);
InitWiFiSta ();
Server. The begin ();
}
Void loop () {
//put your main code here, to run repeatedly:
Char CMD.
Long dis.
Int mark=0;
WiFiClient client=server. The available ();//service initialization
While (client. The connected ()) {
While (client. The available () & gt; 0 {
CMD=client. The read ();
Dis=getTime ()/58.
If (dis & lt; 10) {
Hou ();
} else {
Mark=0;
}
If (mark==0) {
The switch (CMD) {
Case 'q:
Qian ();
break;
Case 'h' :
Hou ();
break;
Case 'z' :
Zuo ();
break;
Case 'y' :
You ();
break;
}
}
}
}
}