Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266Interface HTTPClient Motordriver WebSocketClient mbed
Fork of ESP8266_WebSockets_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "ESP8266Interface.h" 00003 #include "TCPSocketConnection.h" 00004 #include "TCPSocketServer.h" 00005 #include "Websocket.h" 00006 #include "motordriver.h" 00007 #include "HTTPClient.h" 00008 00009 ESP8266Interface wifi(p28,p27,p26,"HOME-0392","D64D858A064D14BF",115200); // TX,RX,Reset,SSID,Password,Baud 00010 Motor r(p22, p18, p17, 1); 00011 Motor m(p21, p20, p19, 1); // pwm, fwd, rev 00012 DigitalOut led1(LED1); 00013 DigitalOut led2(LED2); 00014 DigitalOut led3(LED3); 00015 DigitalOut led4(LED4); 00016 Serial pc(USBTX, USBRX); 00017 00018 void forward() 00019 { 00020 led1 = 1; 00021 r.speed(.6f); 00022 m.speed(.6f); 00023 wait(1.5); 00024 r.coast(); 00025 m.coast(); 00026 led1 = 0; 00027 } 00028 void backward() 00029 { 00030 led2 = 1; 00031 r.speed(-.6f); 00032 m.speed(-.6f); 00033 wait(1.5); 00034 r.coast(); 00035 m.coast(); 00036 led2 = 0; 00037 } 00038 void left() 00039 { 00040 led3 = 1; 00041 wait(.5); 00042 r.speed(.6f); 00043 m.speed(-.6f); 00044 wait(1.5); 00045 r.coast(); 00046 m.coast(); 00047 led3 = 0; 00048 } 00049 void right() 00050 { 00051 led4 = 1; 00052 wait(.5); 00053 r.speed(-.6f); 00054 m.speed(.6f); 00055 wait(1.5); 00056 r.coast(); 00057 m.coast(); 00058 led4 = 0; 00059 } 00060 00061 int main() 00062 { 00063 wifi.init(); //Reset 00064 wifi.connect(); //Use DHCP 00065 pc.printf("IP Address is %s\n", wifi.getIPAddress()); 00066 00067 Websocket ws("ws://10.0.0.16:8080/ws"); 00068 if(!ws.connect()) { 00069 ws.close(); 00070 } else { 00071 char str[10]; 00072 char a; 00073 while(1) { 00074 //ready for new control 00075 sprintf(str, "1"); 00076 pc.printf("%d",str); 00077 ws.send(str); //send to server stating ready for new instruction 00078 //memset(str,0,10); 00079 wait(0.5f); 00080 00081 if(ws.read(str)) { 00082 pc.printf("%s\n", *str); 00083 a = str[0]; 00084 pc.printf("%s",a); 00085 if(a=='1') { 00086 forward(); 00087 } 00088 if(a=='2') { 00089 backward(); 00090 } 00091 if(a=='3') { 00092 left(); 00093 } 00094 if(a=='4') { 00095 right(); 00096 } 00097 } else { 00098 //led1=led2=led3=led4=1; 00099 } 00100 //memset(str,0,10); 00101 wait(3); 00102 } 00103 } 00104 00105 }
Generated on Sat Jul 16 2022 01:54:45 by
 1.7.2
 1.7.2 
    