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: EthernetInterface HTTPClient mbed-rtos mbed
Fork of FreedomK64F_Ethernet by
main.cpp
- Committer:
- Spookmx
- Date:
- 2014-11-27
- Revision:
- 1:9eb6f83066db
- Parent:
- 0:ce7b80583a29
- Child:
- 2:4e65bd216494
File content as of revision 1:9eb6f83066db:
#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"
EthernetInterface eth;
HTTPClient http;
char str[512];
// FRDM17511 I/O
DigitalOut ENABLED(PTC7);
DigitalOut READY(PTC5);
DigitalOut OUT1(D2);
DigitalOut OUT2(D3);
DigitalIn SNS(PTC0);
// LED
DigitalOut led_red(LED_RED);
DigitalOut led_green(LED_GREEN);
DigitalOut led_blue(LED_BLUE);
Serial pc(USBTX, USBRX);
void check_color(void)
{
//GET data
printf("\nTrying to fetch page...\n");
int ret = http.get("http://joseromero.mx/checkColor.php", str, 128);
if (!ret) {
if(strcmp(str,"AUTHORIZED")== 0) {
led_green = 1;
led_red = 1;
led_blue = 0; // Found new tweet, we turn the led to blue
OUT1 = 1;
OUT2 = 0;
wait(3); // Leaves the motor ON for 3 seconds
OUT1 = 0; // We turn it off
OUT2 = 0;
led_green = 0; // We go back to green light
led_red = 1;
led_blue = 1;
} else if(strcmp(str,"NOT AUTHORIZED")== 0) {
led_green = 1;
led_red = 0; // No new tweets, RED light
led_blue = 1;
wait(3);
led_green = 0; // We go back to green light
led_red = 1;
led_blue = 1;
} else if(strcmp(str,"NO DATA")== 0) {
led_green = 1;
led_red = 0; // No data from the server, goes to PURPLE
led_blue = 0;
wait(3);
led_green = 0; // We go back to green light
led_red = 1;
led_blue = 1;
} else {
led_green = 0;
led_red = 0;
led_blue = 1;
}
printf("Page fetched successfully - read %d characters\n", strlen(str));
printf("Result: %s\n", str);
} else {
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
}
}
int main()
{
eth.init(); //Use DHCP
eth.connect();
led_green = 0;
led_red = 1;
led_blue = 1;
ENABLED = 1;
READY = 1;
//pc.printf("Starting setting color.\n");
while (true) {
check_color();
wait(5); // Check for a tweet every 5 seconds
}
}
