Created
March 30, 2014 07:28
-
-
Save icoxfog417/9869034 to your computer and use it in GitHub Desktop.
mbed joy stick and http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
#include "EthernetInterface.h" | |
#include "HTTPClient.h" | |
#include "C12832.h" | |
#include <stdio.h> | |
InterruptIn up(p15); | |
InterruptIn down(p12); | |
InterruptIn left(p13); | |
InterruptIn right(p16); | |
//display out object | |
C12832 lcd(p5, p7, p6, p8, p11); | |
//joy stick | |
BusIn joy(p15,p12,p13,p16); | |
//DigitalIn fire(p14); | |
BusOut leds(LED1,LED2,LED3,LED4); | |
//flag for process | |
int inProc = -1; | |
int selecteJoy = -1; | |
//global variable | |
char key[512] = "0x7Y4bSH1H"; | |
char url[100] = "http://sumoapi-c9-icoxfog417.c9.io/remocon"; | |
char machine[10] = "mbed1"; | |
int color[4] = {0,0,0,0}; | |
void invoke(){ | |
//handle joy stick event; | |
leds = joy; | |
switch(joy){ | |
case 1 : selecteJoy = 0; break; | |
case 2 : selecteJoy = 1; break; | |
case 4 : selecteJoy = 2; break; | |
case 8 : selecteJoy = 3; break; | |
} | |
inProc = 1; | |
} | |
int main(void) { | |
//initialize lcd | |
lcd.cls(); | |
char query[1024] = ""; | |
HTTPText response(key, 512); | |
//internet access | |
EthernetInterface eth; | |
HTTPClient http; | |
eth.init(); //Use DHCP | |
eth.connect(); | |
//game start | |
lcd.printf("game start!! %s \n", eth.getIPAddress()); | |
//event handlerz | |
up.rise(&invoke); | |
down.rise(&invoke); | |
left.rise(&invoke); | |
right.rise(&invoke); | |
while(true){ | |
if(inProc < 0){ | |
wait(0.25); | |
continue; | |
} | |
//make post data | |
color[selecteJoy] += 1; | |
//build query | |
if(key[0] == 0){ | |
sprintf(query, "%s?machine=%s&red=%i&blue=%i&green=%i&yellow=%i",url,machine,color[0],color[1],color[2],color[3]); | |
}else{ | |
sprintf(query, "%s?machine=%s&key=%s&red=%i&blue=%i&green=%i&yellow=%i",url,machine,key,color[0],color[1],color[2],color[3]); | |
} | |
printf("%s\n",query); | |
//send data to cloud | |
char dummy[128]; | |
int ret = http.get(query, dummy , 128); | |
if (!ret) | |
{ | |
lcd.locate(0,15); | |
lcd.printf("updated! objectId is %s" , dummy); | |
} | |
else | |
{ | |
lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); | |
} | |
//flag off | |
inProc = -1; | |
} | |
eth.disconnect(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment