final
Dependencies: KS0108 WIZnet_Library mbed
Fork of bigthingRec by
Diff: main.cpp
- Revision:
- 5:c0f61c21e78c
- Parent:
- 4:a4ec8ea99d70
- Child:
- 6:6744a42b8824
diff -r a4ec8ea99d70 -r c0f61c21e78c main.cpp --- a/main.cpp Thu May 12 06:22:14 2016 +0000 +++ b/main.cpp Fri May 20 18:30:52 2016 +0000 @@ -3,7 +3,7 @@ #include "WIZnetInterface.h" unsigned char MAC_Addr[6] = {0x90,0x08,0xDC,0x12,0x07,0x07}; -PwmOut led(PTA12); + char* Update_Key = "L055HRYFCBL1LTM2"; char* ServerIP = "api.thingspeak.com"; int Count = 15; @@ -19,36 +19,41 @@ AnalogIn ax(PTC1); AnalogIn ain(PTC2); + +BusOut SevSeg1(PTD4,PTA12,PTA4,PTA5); +//BusOut SevSeg2(PTC8,PTC9,PTA13,PTD5); + +//DigitalOut toutb(PTA1); +PwmOut ledout(LED1); + float luxm(void) { - + float vr=0; + float lr=0; + float vol[14]={0,1.1,1.23,1.3,1.45,1.6,1.81,2.06,2.31,2.62,2.81,3.02,3.1,3.3}; + float lux[14]={27000,20000,16000,11000,7000,4000,1500,833,578,201,104,40,23,0}; -float vr=0; -float lr=0; -float vol[13]={0,1.1,1.23,1.3,1.45,1.6,1.81,2.06,2.31,2.62,2.81,3.02,3.1}; -float lux[13]={27000,20000,16000,11000,7000,4000,1500,833,578,201,104,40,23}; + int i; + float m=0; -int i; -float m=0; - -vr=ain*3.3; + vr=ain*3.3; -for(i=0; vr> vol[i];i++); -m = ((lux[i]-lux[i+1])/(vol[i]-vol[i+1])); -lr=lux[i+1]+(m*(vr-(vol[i+1]))); + for(i=0; vr>= vol[i];i++); + m = ((lux[i]-lux[i+1])/(vol[i]-vol[i+1])); + lr=lux[i+1]+(m*(vr-(vol[i+1]))); -return lr; + return lr; } uint8_t val; - + int main() { - while(1) - { pc.printf("Start\r\n"); - val=0x00; - int ret = ethernet.init(MAC_Addr); + + do + { + int ret = ethernet.init(MAC_Addr); if (!ret) { @@ -58,6 +63,7 @@ { pc.printf("IP: %s, MASK: %s, GW: %s\r\n", ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); + val=0x00; } else { @@ -70,79 +76,127 @@ { pc.printf("Error ethernet.init() - ret = %d\r\n", ret); val=0xff;; - } - - - TCPSocketConnection sock; + } + }while(val==0xff); + + TCPSocketConnection sock; + do + { sock.connect("api.thingspeak.com", 80); if(sock.is_connected()) - pc.printf("Socket Connected\n\r"); + { + pc.printf("Socket Connected\n\r"); + val=0x00; + } else - pc.printf("Socket NoT Connected\n\r"); + { + pc.printf("Socket NoT Connected\n\r"); + val=0xff; + } - - - char buffer[300]; + }while(val==0xff); + + char buffer[300]; int ret_t; char http_cmd[256]; - int l=luxm(); - + int i; + int j=0; + while(1) + { - - while(val==0x00) - { - float x=ain; - led=x; - - if(micro.readable()) - { - val=(micro.getc()); - if(val == 0x01) - { - - pc.printf("%.2f ",l); - - - - sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field1= %.2f HTTP/1.0\n\n",luxm()); - printf("Running - %s\r\n",http_cmd); - sock.send_all(http_cmd, sizeof(http_cmd)-1); + while(val==0x00) + { + for(i=j;i<20;i++) + { + float l=ain; + float t=ax; + + ledout=1.0-l; + + if(l>=0 && l<0.25) + SevSeg1 = 0x01; + else if (l>=0.25 && l<0.5) + SevSeg1 = 0x03 ; + else if (l>=0.5 && l<0.75) + SevSeg1 = 0x07; + else if (l>=0.75 && l<=1.0) + SevSeg1 = 0x00; + + if(micro.readable()) + { + val=(micro.getc()); + j=i; + i=25; + } + + else + wait(1); + } - ret_t = sock.receive(buffer, sizeof(buffer)-1); - buffer[ret_t] = '\0'; - printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); - } + if(val == 0x00) + { + pc.printf("%.2f ",luxm()); + + sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field1= %.2f HTTP/1.0\n\n",luxm()); + printf("Running - %s\r\n",http_cmd); + sock.send_all(http_cmd, sizeof(http_cmd)-1); + + ret_t = sock.receive(buffer, sizeof(buffer)-1); + buffer[ret_t] = '\0'; + printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); - else if(val == 0x02) - { - pc.printf("%.2f ",ax*3.3); - + + pc.printf("%.2f ",ax*3.3); - sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field2= %.2f HTTP/1.0\n\n",ax*3.3*17); - printf("Running - %s\r\n",http_cmd); - sock.send_all(http_cmd, sizeof(http_cmd)-1); + sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field2= %.2f HTTP/1.0\n\n",ax*3.3*17); + printf("Running - %s\r\n",http_cmd); + sock.send_all(http_cmd, sizeof(http_cmd)-1); + + ret_t = sock.receive(buffer, sizeof(buffer)-1); + buffer[ret_t] = '\0'; + printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); + val=0x00; + j=0; + } + else if(val == 0x01) + { + pc.printf("%.2f ",luxm()); + + sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field1= %.2f HTTP/1.0\n\n",luxm()); + printf("Running - %s\r\n",http_cmd); + sock.send_all(http_cmd, sizeof(http_cmd)-1); - ret_t = sock.receive(buffer, sizeof(buffer)-1); - buffer[ret_t] = '\0'; - printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); - + ret_t = sock.receive(buffer, sizeof(buffer)-1); + buffer[ret_t] = '\0'; + printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); + val=0x00; + } + + else if(val == 0x02) + { + pc.printf("%.2f ",ax*3.3); + + sprintf(http_cmd,"GET /update?key=L055HRYFCBL1LTM2&field2= %.2f HTTP/1.0\n\n",ax*3.3*17); + printf("Running - %s\r\n",http_cmd); + sock.send_all(http_cmd, sizeof(http_cmd)-1); + + ret_t = sock.receive(buffer, sizeof(buffer)-1); + buffer[ret_t] = '\0'; + printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); + val=0x00; + } } + + } + + //sock.close(); + + //ethernet.disconnect(); + //printf("Socket Closed"); +} - else - val=0x00; - - wait(2); - - } - - } - - sock.close(); - - ethernet.disconnect(); - printf("Socket Closed"); - } - } \ No newline at end of file + // float x=ain; + //led=x; \ No newline at end of file