This program is used to control the car remotely via telnet using wifi.
Dependencies: C12832_lcd WiflyInterface mbed
Fork of Mode-3_Remote_Control by
main.cpp
- Committer:
- bhakti08
- Date:
- 2014-06-09
- Revision:
- 8:c20dc0f4bc92
- Parent:
- 7:7f0988b083cb
File content as of revision 8:c20dc0f4bc92:
//This Program is used to turn the LED ON/OFF via telent (Wifly connected)
#include "mbed.h"
#include "WiflyInterface.h"
#include "C12832_lcd.h"
#include <string.h>
#define ECHO_SERVER_PORT 7
#define FWD 3
#define REV 4
#define LEFT 1
#define RIGHT 2
#define STOP 0
#define STRAIGHT_WHEEL 5
#define servo_1 6
#define servo_2 7
PwmOut servo(p22);
DigitalOut dir(LED1);
BusOut motor(p5,p6,p7);
C12832_LCD lcd;
Serial pc(USBTX,USBRX);
//#define FWD 1
//#define REV 0
/* wifly interface:
* - p9 and p10 are for the serial communication
* - p19 is for the reset pin
* - p26 is for the connection status
* - "mbed" is the ssid of the network
* - "password" is the password
* - WPA is the security
*/
//apps board
WiflyInterface wifly(p9, p10, p30, p29, "MY_WIFI", "", NONE);
//pololu
//WiflyInterface wifly(p28, p27, p26, NC, "iotlab", "42F67YxLX4AawRdcj", WPA);
int main() {
wifly.init(); //Use DHCP
printf("1\r\n");
while (!wifly.connect());
lcd.printf("IP Address is %s\n\r", wifly.getIPAddress());
TCPSocketServer server;
server.bind(ECHO_SERVER_PORT);
server.listen();
lcd.cls();
lcd.printf("\nWait for new connection...\n");
TCPSocketConnection client;
server.accept(client);
lcd.locate(0,20);
lcd.printf("Server accept\r\n");
char buffer[256];
servo.period_us(50);
motor = STOP;
while (true) {
//if (client.available()){
int n = client.receive(buffer, sizeof(buffer));
if (n <= 0) continue;
buffer[n] = 0;
pc.printf("String is : %s\r\n",buffer);
client.send_all(buffer, n);
if (!(strcmp (buffer, "w")))
motor = FWD;
else if (!(strcmp(buffer,"x")))
motor = REV;
else if (!(strcmp(buffer,"z")))
motor = STRAIGHT_WHEEL;
else if (!(strcmp(buffer,"d")))
motor = RIGHT;
else if (!(strcmp(buffer,"a")))
motor = LEFT;
else if (!(strcmp(buffer,"s")))
motor = STOP;
else if (!(strcmp(buffer,"o")))
motor = servo_1;
else if (!(strcmp(buffer,"p")))
motor = servo_2;
//}
servo.pulsewidth_us(10);
wait_us(1);
}
}
