I just started using the CC3000 wifi breakout board. My code works as long as i dont use rest.variable() function. When i apply the function the ADC stops working (in the loop function i wrote an LED brightness changer code, and the LED's bright wont change).
The code is basicly this example:
https://github.com/openhomeautomation/CC3000_REST
The code:
Code: Select all
// Import required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <CC3000_MDNS.h>
#include <aREST.h>
// These are the pins for the CC3000 chip if you are using a breakout board
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Create CC3000 instance
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
// Your WiFi SSID and password
#define WLAN_SSID "****"
#define WLAN_PASS "****"
#define WLAN_SECURITY WLAN_SEC_WEP
// The port to listen for incoming TCP connections
#define LISTEN_PORT 80
// Create aREST instance
aREST rest = aREST();
// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);
// DNS responder instance
MDNSResponder mdns;
void setup(void)
{
Serial.begin(115200);
// Set up CC3000 and get connected to the wireless network.
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
while (!cc3000.checkDHCP())
{
delay(100);
}
Serial.println();
// Print CC3000 IP address
while (! displayConnectionDetails()) {
delay(1000);
}
// Start multicast DNS responder
if (!mdns.begin("arduino", cc3000)) {
while(1);
}
// Start server
restServer.begin();
Serial.println(F("Listening for connections..."));
}
int sensorvalue=0, outputvalue=0;
int seg=1;
void loop()
{
// Handle any multicast DNS requests
mdns.update();
// Handle REST calls
Adafruit_CC3000_ClientRef client = restServer.available();
rest.handle(client);
sensorvalue = analogRead(A0);
outputvalue = map(sensorvalue, 780, 0, 0, 255);
analogWrite(9, outputvalue); //Changes LED brightness
rest.variable("seg", &seg);
}
// Print connection details of the CC3000 chip
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;
}
}