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: C12832_lcd WiflyInterface mbed
Fork of Mode-3_Remote_Control by
main.cpp
00001 //This Program is used to turn the LED ON/OFF via telent (Wifly connected) 00002 #include "mbed.h" 00003 #include "WiflyInterface.h" 00004 #include "C12832_lcd.h" 00005 #include <string.h> 00006 00007 #define ECHO_SERVER_PORT 7 00008 #define FWD 3 00009 #define REV 4 00010 #define LEFT 1 00011 #define RIGHT 2 00012 #define STOP 0 00013 #define STRAIGHT_WHEEL 5 00014 #define servo_1 6 00015 #define servo_2 7 00016 00017 00018 PwmOut servo(p22); 00019 DigitalOut dir(LED1); 00020 BusOut motor(p5,p6,p7); 00021 C12832_LCD lcd; 00022 Serial pc(USBTX,USBRX); 00023 //#define FWD 1 00024 //#define REV 0 00025 00026 00027 /* wifly interface: 00028 * - p9 and p10 are for the serial communication 00029 * - p19 is for the reset pin 00030 * - p26 is for the connection status 00031 * - "mbed" is the ssid of the network 00032 * - "password" is the password 00033 * - WPA is the security 00034 */ 00035 //apps board 00036 WiflyInterface wifly(p9, p10, p30, p29, "MY_WIFI", "", NONE); 00037 00038 //pololu 00039 //WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA); 00040 00041 int main() { 00042 00043 wifly.init(); //Use DHCP 00044 printf("1\r\n"); 00045 while (!wifly.connect()); 00046 lcd.printf("IP Address is %s\n\r", wifly.getIPAddress()); 00047 00048 TCPSocketServer server; 00049 00050 server.bind(ECHO_SERVER_PORT); 00051 server.listen(); 00052 lcd.cls(); 00053 lcd.printf("\nWait for new connection...\n"); 00054 TCPSocketConnection client; 00055 server.accept(client); 00056 lcd.locate(0,20); 00057 lcd.printf("Server accept\r\n"); 00058 00059 char buffer[256]; 00060 servo.period_us(50); 00061 motor = STOP; 00062 while (true) { 00063 //if (client.available()){ 00064 int n = client.receive(buffer, sizeof(buffer)); 00065 if (n <= 0) continue; 00066 buffer[n] = 0; 00067 pc.printf("String is : %s\r\n",buffer); 00068 00069 client.send_all(buffer, n); 00070 if (!(strcmp (buffer, "w"))) 00071 motor = FWD; 00072 else if (!(strcmp(buffer,"x"))) 00073 motor = REV; 00074 else if (!(strcmp(buffer,"z"))) 00075 motor = STRAIGHT_WHEEL; 00076 else if (!(strcmp(buffer,"d"))) 00077 motor = RIGHT; 00078 else if (!(strcmp(buffer,"a"))) 00079 motor = LEFT; 00080 else if (!(strcmp(buffer,"s"))) 00081 motor = STOP; 00082 else if (!(strcmp(buffer,"o"))) 00083 motor = servo_1; 00084 else if (!(strcmp(buffer,"p"))) 00085 motor = servo_2; 00086 //} 00087 servo.pulsewidth_us(10); 00088 wait_us(1); 00089 } 00090 }
Generated on Sat Jul 23 2022 14:43:38 by
1.7.2
