meter_controller_223_LED

Dependencies:   EthernetInterface mbed-rtos mbed

Committer:
shindo
Date:
Thu Nov 08 07:41:57 2012 +0000
Revision:
1:95407c4ef69e
Parent:
0:e0c9a84c55c9
Child:
2:c1d4ea63ab89
switch case?????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shindo 0:e0c9a84c55c9 1 #include "mbed.h"
shindo 0:e0c9a84c55c9 2 #include "mbed.h"
shindo 0:e0c9a84c55c9 3 #include "EthernetInterface.h"
shindo 0:e0c9a84c55c9 4
shindo 0:e0c9a84c55c9 5 #define ECHO_SERVER_PORT 10373
shindo 0:e0c9a84c55c9 6
shindo 0:e0c9a84c55c9 7 DigitalOut digitalclock_colon (p17);
shindo 0:e0c9a84c55c9 8 DigitalOut digitalclock (p18);
shindo 0:e0c9a84c55c9 9 DigitalOut signal_LED_L (p19);
shindo 0:e0c9a84c55c9 10 DigitalOut signal_LED_R (p20);
shindo 0:e0c9a84c55c9 11
shindo 0:e0c9a84c55c9 12 PwmOut meter_LED_outside (p21);
shindo 0:e0c9a84c55c9 13 PwmOut meter_LED_inside (p22);
shindo 0:e0c9a84c55c9 14 PwmOut needle_LED (p23);
shindo 0:e0c9a84c55c9 15 PwmOut range_LED_1 (p24);
shindo 0:e0c9a84c55c9 16 PwmOut range_LED_2 (p25);
shindo 0:e0c9a84c55c9 17 PwmOut range_LED_3 (p26);
shindo 0:e0c9a84c55c9 18
shindo 0:e0c9a84c55c9 19 int main()
shindo 0:e0c9a84c55c9 20 {
shindo 0:e0c9a84c55c9 21 EthernetInterface eth;
shindo 0:e0c9a84c55c9 22 eth.init(); //Use DHCP
shindo 0:e0c9a84c55c9 23 eth.connect();
shindo 0:e0c9a84c55c9 24 printf("IP Address is %s\n", eth.getIPAddress());
shindo 0:e0c9a84c55c9 25
shindo 0:e0c9a84c55c9 26 TCPSocketServer server;
shindo 0:e0c9a84c55c9 27 server.bind(ECHO_SERVER_PORT);
shindo 0:e0c9a84c55c9 28 server.listen();
shindo 0:e0c9a84c55c9 29
shindo 0:e0c9a84c55c9 30 meter_LED_outside.period_ms (1);
shindo 0:e0c9a84c55c9 31
shindo 0:e0c9a84c55c9 32 int i = 0;
shindo 0:e0c9a84c55c9 33 //int j = 0;
shindo 1:95407c4ef69e 34 int mode = (buffer[0] - 'A');
shindo 0:e0c9a84c55c9 35
shindo 0:e0c9a84c55c9 36 while (1) {
shindo 0:e0c9a84c55c9 37 TCPSocketConnection client;
shindo 0:e0c9a84c55c9 38 server.accept(client);
shindo 0:e0c9a84c55c9 39 client.set_blocking(false, 1500);
shindo 0:e0c9a84c55c9 40 printf("Client connected %s\n", client.get_address());
shindo 0:e0c9a84c55c9 41
shindo 0:e0c9a84c55c9 42 char buffer[256];
shindo 0:e0c9a84c55c9 43 while (true) {
shindo 0:e0c9a84c55c9 44 int n = client.receive(buffer, sizeof(buffer));
shindo 0:e0c9a84c55c9 45
shindo 0:e0c9a84c55c9 46 if (n > 0) {
shindo 1:95407c4ef69e 47 //int target = (buffer[1] - '0') * 100 + (buffer[2] - '0') * 10 + (buffer[3] - '0');
shindo 1:95407c4ef69e 48 if (i == 1) {
shindo 1:95407c4ef69e 49 while (1) {
shindo 1:95407c4ef69e 50 digitalclock_colon = 1;
shindo 1:95407c4ef69e 51 wait (0.5);
shindo 1:95407c4ef69e 52 digitalclock_colon = 0;
shindo 1:95407c4ef69e 53 wait (0.5);
shindo 1:95407c4ef69e 54 }
shindo 1:95407c4ef69e 55 }
shindo 0:e0c9a84c55c9 56 if (buffer[0] == 'A') {
shindo 1:95407c4ef69e 57
shindo 0:e0c9a84c55c9 58 if (i <= 0) {
shindo 0:e0c9a84c55c9 59 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 60 meter_LED_outside = p;
shindo 0:e0c9a84c55c9 61 wait(0.01);
shindo 0:e0c9a84c55c9 62 }
shindo 0:e0c9a84c55c9 63 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 64 meter_LED_inside = p;
shindo 0:e0c9a84c55c9 65 wait(0.01);
shindo 0:e0c9a84c55c9 66 }
shindo 0:e0c9a84c55c9 67 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 68 range_LED_3 = p;
shindo 0:e0c9a84c55c9 69 wait(0.01);
shindo 0:e0c9a84c55c9 70 }
shindo 0:e0c9a84c55c9 71 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 72 range_LED_2 = p;
shindo 0:e0c9a84c55c9 73 wait(0.01);
shindo 0:e0c9a84c55c9 74 }
shindo 0:e0c9a84c55c9 75 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 76 range_LED_1 = p;
shindo 0:e0c9a84c55c9 77 wait(0.01);
shindo 0:e0c9a84c55c9 78 }
shindo 0:e0c9a84c55c9 79 for(float p = 0.0f; p < 1.0f; p += 0.01f) {
shindo 0:e0c9a84c55c9 80 needle_LED = p;
shindo 0:e0c9a84c55c9 81 wait(0.01);
shindo 0:e0c9a84c55c9 82 }
shindo 0:e0c9a84c55c9 83 for(float p = 1.0f; p > 0.0f; p -= 0.01f) {
shindo 0:e0c9a84c55c9 84 meter_LED_outside = p;
shindo 0:e0c9a84c55c9 85 meter_LED_inside = p;
shindo 0:e0c9a84c55c9 86 range_LED_3 = p;
shindo 0:e0c9a84c55c9 87 range_LED_2 = p;
shindo 0:e0c9a84c55c9 88 range_LED_1 = p;
shindo 0:e0c9a84c55c9 89 needle_LED = p;
shindo 0:e0c9a84c55c9 90 wait(0.01);
shindo 0:e0c9a84c55c9 91 }
shindo 0:e0c9a84c55c9 92 signal_LED_L = 1;
shindo 0:e0c9a84c55c9 93 signal_LED_R = 1;
shindo 0:e0c9a84c55c9 94 wait (0.5);
shindo 0:e0c9a84c55c9 95 signal_LED_L = 0;
shindo 0:e0c9a84c55c9 96 signal_LED_R = 0;
shindo 0:e0c9a84c55c9 97 wait (0.5);
shindo 0:e0c9a84c55c9 98
shindo 0:e0c9a84c55c9 99 wait(1.0);
shindo 0:e0c9a84c55c9 100 for(float p = 0.0f; p < 0.2f; p += 0.01f) {
shindo 0:e0c9a84c55c9 101 meter_LED_outside = p;
shindo 0:e0c9a84c55c9 102 meter_LED_inside = p;
shindo 0:e0c9a84c55c9 103 // range_LED_3 = p;
shindo 0:e0c9a84c55c9 104 range_LED_2 = p;
shindo 0:e0c9a84c55c9 105 //range_LED_1 = p;
shindo 0:e0c9a84c55c9 106 needle_LED = (p + 0.8);
shindo 0:e0c9a84c55c9 107 wait(0.05);
shindo 0:e0c9a84c55c9 108 }
shindo 1:95407c4ef69e 109 i = 1;
shindo 1:95407c4ef69e 110 digitalclock = 1;
shindo 0:e0c9a84c55c9 111 }
shindo 0:e0c9a84c55c9 112 } else if (buffer[0] == 'B') {
shindo 0:e0c9a84c55c9 113 digitalclock = 0;
shindo 0:e0c9a84c55c9 114 digitalclock_colon = 0;
shindo 0:e0c9a84c55c9 115 for(float p = 0.8f; p > 0.0f; p -= 0.01f) {
shindo 0:e0c9a84c55c9 116 meter_LED_outside = p;
shindo 0:e0c9a84c55c9 117 meter_LED_inside = p;
shindo 0:e0c9a84c55c9 118 range_LED_3 = p;
shindo 0:e0c9a84c55c9 119 range_LED_2 = p;
shindo 0:e0c9a84c55c9 120 range_LED_1 = p;
shindo 0:e0c9a84c55c9 121 needle_LED = p;
shindo 0:e0c9a84c55c9 122 wait(0.01);
shindo 0:e0c9a84c55c9 123 }
shindo 1:95407c4ef69e 124 } else if (buffer[0] == 'F') {
shindo 1:95407c4ef69e 125 meter_LED_outside = (target / 10.0)-0.2;
shindo 1:95407c4ef69e 126 } else if (buffer[0] == 'G') {
shindo 1:95407c4ef69e 127 meter_LED_inside = (target / 10.0)-0.2;
shindo 1:95407c4ef69e 128 }
shindo 0:e0c9a84c55c9 129
shindo 0:e0c9a84c55c9 130 }
shindo 0:e0c9a84c55c9 131 }
shindo 0:e0c9a84c55c9 132 }
shindo 1:95407c4ef69e 133 }
shindo 1:95407c4ef69e 134
shindo 1:95407c4ef69e 135