meter_controller_223_LED

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
shindo
Date:
Wed Nov 07 11:12:10 2012 +0000
Child:
1:95407c4ef69e
Commit message:
meter_controller_222_LED

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Nov 07 11:12:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 07 11:12:10 2012 +0000
@@ -0,0 +1,128 @@
+#include "mbed.h"
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+#define ECHO_SERVER_PORT   10373
+
+DigitalOut digitalclock_colon (p17);
+DigitalOut digitalclock (p18);
+DigitalOut signal_LED_L (p19);
+DigitalOut signal_LED_R (p20);
+
+PwmOut meter_LED_outside (p21);
+PwmOut meter_LED_inside (p22);
+PwmOut needle_LED (p23);
+PwmOut range_LED_1 (p24);
+PwmOut range_LED_2 (p25);
+PwmOut range_LED_3 (p26);
+
+int main()
+{
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n", eth.getIPAddress());
+
+    TCPSocketServer server;
+    server.bind(ECHO_SERVER_PORT);
+    server.listen();
+
+    meter_LED_outside.period_ms (1);
+
+    int i = 0;
+    //int j = 0;
+
+    while (1) {
+        TCPSocketConnection client;
+        server.accept(client);
+        client.set_blocking(false, 1500);
+        printf("Client connected %s\n", client.get_address());
+
+        char buffer[256];
+        while (true) {
+            int n = client.receive(buffer, sizeof(buffer));
+
+            if (n > 0) {
+                int target = (buffer[1] - '0') * 100 + (buffer[2] - '0') * 10 + (buffer[3] - '0');
+
+                if (buffer[0] == 'A') {
+                    digitalclock = 1;
+                    digitalclock_colon = 1;
+                    wait (0.5);
+                    digitalclock_colon = 0;
+                    wait (0.5);
+                    if (i <= 0) {
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            meter_LED_outside = p;
+                            wait(0.01);
+                        }
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            meter_LED_inside = p;
+                            wait(0.01);
+                        }
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            range_LED_3 = p;
+                            wait(0.01);
+                        }
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            range_LED_2 = p;
+                            wait(0.01);
+                        }
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            range_LED_1 = p;
+                            wait(0.01);
+                        }
+                        for(float p = 0.0f; p < 1.0f; p += 0.01f) {
+                            needle_LED = p;
+                            wait(0.01);
+                        }
+                        for(float p = 1.0f; p > 0.0f; p -= 0.01f) {
+                            meter_LED_outside = p;
+                            meter_LED_inside = p;
+                            range_LED_3 = p;
+                            range_LED_2 = p;
+                            range_LED_1 = p;
+                            needle_LED = p;
+                            wait(0.01);
+                        }
+                        signal_LED_L = 1;
+                        signal_LED_R = 1;
+                        wait (0.5);
+                        signal_LED_L = 0;
+                        signal_LED_R = 0;
+                        wait (0.5);
+
+                        wait(1.0);
+                        for(float p = 0.0f; p < 0.2f; p += 0.01f) {
+                            meter_LED_outside = p;
+                            meter_LED_inside = p;
+                            // range_LED_3 = p;
+                            range_LED_2 = p;
+                            //range_LED_1 = p;
+                            needle_LED = (p + 0.8);
+                            wait(0.05);
+                        }
+                        i++;
+                    }
+                } else if (buffer[0] == 'B') {
+                    digitalclock = 0;
+                    digitalclock_colon = 0;
+                    for(float p = 0.8f; p > 0.0f; p -= 0.01f) {
+                        meter_LED_outside = p;
+                        meter_LED_inside = p;
+                        range_LED_3 = p;
+                        range_LED_2 = p;
+                        range_LED_1 = p;
+                        needle_LED = p;
+                        wait(0.01);
+                    }
+
+                } else if (buffer[0] == 'F') {
+                    meter_LED_outside = target / 10.0;
+                } else if (buffer[0] == 'G') {
+                    meter_LED_inside = target / 10.0;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Nov 07 11:12:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 07 11:12:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file