the codes
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <stdlib.h>
const int IN1=4;
const int IN2=2;
const int IN3=7;
const int IN4=8;
/*const int INA= A0;
const int INB= A1;
const int INC= A2;
const int IND= A3;*/
char input;
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
#define WLAN_SSID "aa" // cannot be longer than 32 characters!
#define WLAN_PASS "11"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define LISTEN_PORT 80 // What TCP port to listen on for connections.
// The HTTP protocol uses port 80 by default.
Adafruit_CC3000_Server httpServer(LISTEN_PORT);
String readString;
void setup()
{
pinMode( IN1 ,OUTPUT);// Right Motor 1st wire
pinMode( IN2 ,OUTPUT);// Right Motor 2nd wire
pinMode( IN3 ,OUTPUT);// left Motor 1st wire
pinMode( IN4 ,OUTPUT);// left Motor 2nd wire
Serial.begin(115200);
// analogWrite(E1, 0);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
// Initialise the module
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
// Display the IP address DNS, Gateway, etc.
while (! displayConnectionDetails()) {
delay(1000);
}
// Start listening for connections
httpServer.begin();
Serial.println(F("Listening for connections..."));
}
void loop() {
// Try to get a client which is connected.
Adafruit_CC3000_ClientRef client = httpServer.available();
if (client)
{
delay(5);
Serial.println(F("Client connected."));
// Process this request until it completes or times out.
// Note that this is explicitly limited to handling one request at a time!
// An HTTP request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
//Serial.write(c);
// If you've gotten to the end of the line (received a newline
// character) and the line is blank, the HTTP request has ended,
// so you can send a reply.
if (readString.length() < 100) {
readString += c;
Serial.print(c);
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE HTML>");
//send the HTML stuff
client.println("<html><head><title>Randi Control Panel</title><style type=\"text/css\">");
client.println("body { font-family: sans-serif }");
/*
client.println("h1 { font-size: 14pt; }");
client.println("p { font-size: 10pt; }");
client.println("a { color: #2020FF; }");
client.println("</style>");
client.println("</head><body text=\"#A0A0A0\" bgcolor=\"#080808\">");
*/
client.println("<h1>Randi Controls</h1>
");
client.println(F("<form method=\"link\" action=\"/forward\"><input type=\"submit\" value=\"Go!\"></form>"));
client.println(F("<form method=\"link\" action=\"/backward\"><input type=\"submit\" value=\"Reverse!\"></form>"));
client.println(F("<form method=\"link\" action=\"/stop\"><input type=\"submit\" value=\"Stop\"></form>"));
client.println(F("<form method=\"link\" action=\"/left\"><input type=\"submit\" value=\"Front Left\"></form>"));
client.println(F("<form method=\"link\" action=\"/right\"><input type=\"submit\" value=\"Front Right\"></form>"));
//client.println("<form method=\"link\" action=\"/Bleft\"><input type=\"submit\" value=\"Back Left\"></form>");
// client.println("<form method=\"link\" action=\"/Bright\"><input type=\"submit\" value=\"Back Right\"></form>");
client.println("
");
client.println("</body></html>");
client.println();
break;
}
if (c == '\n') {
// You're starting a new line.
currentLineIsBlank = true;
}
else if (c != '\r') {
// You've gotten a character on the current line.
currentLineIsBlank = false;
}
}
}
// Give the web browser time to receive the data.
process(client);
readString = "";
client.close();
}
}
void process (Adafruit_CC3000_ClientRef client)
{
if(readString.length() > 0){
if (readString.indexOf("/forward") > 0)
{
// put your main code here, to run repeatedly:
/*if (Serial.available()) {
// read the most recent character
*/
// input = Serial.read();
// switch based on the character
// switch(input){
// case 'F':
// forward
analogWrite(IN1,0);
analogWrite(IN2,255);
analogWrite(IN3,255);
analogWrite(IN4,0);
//break;
}
else if (readString.indexOf("/backward") > 0)
{
// case 'B': // backwards
// v=Serial.read();
analogWrite(IN1,200);
analogWrite(IN2,0);
analogWrite(IN3,0);
analogWrite(IN4,200);
// break;
}
// case 'S': // stop
else if (readString.indexOf("/stop") > 0)
{
analogWrite(IN1,0);
analogWrite(IN2,0);
analogWrite(IN3,0);
analogWrite(IN4,0);
// break;
}
// case 'L': // left
else if (readString.indexOf("/left") > 0)
{
analogWrite(IN1,0);
analogWrite(IN2,150);
analogWrite(IN3,0);
analogWrite(IN4,200);
}
// break;
// case 'R': // right
else if (readString.indexOf("/right") > 0)
{
analogWrite(IN1,150);
analogWrite(IN2,LOW);
analogWrite(IN3,200);
analogWrite(IN4,LOW);
}// break;
// default: // if character not recognized then stop
else if (readString.indexOf("/stop") > 0)
{
analogWrite(IN1, 0);
analogWrite(IN3, 0);
// break;
}
}}
// Tries to read the IP address and other connection details
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}