meter_controller_223_LED
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp@2:c1d4ea63ab89, 2012-11-08 (annotated)
- Committer:
- shindo
- Date:
- Thu Nov 08 08:10:37 2012 +0000
- Revision:
- 2:c1d4ea63ab89
- Parent:
- 1:95407c4ef69e
- Child:
- 3:82cf87db7ef4
switch case ? if ?
Who changed what in which revision?
User | Revision | Line number | New 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 | while (1) { |
shindo | 0:e0c9a84c55c9 | 33 | TCPSocketConnection client; |
shindo | 0:e0c9a84c55c9 | 34 | server.accept(client); |
shindo | 0:e0c9a84c55c9 | 35 | client.set_blocking(false, 1500); |
shindo | 0:e0c9a84c55c9 | 36 | printf("Client connected %s\n", client.get_address()); |
shindo | 0:e0c9a84c55c9 | 37 | |
shindo | 0:e0c9a84c55c9 | 38 | char buffer[256]; |
shindo | 0:e0c9a84c55c9 | 39 | while (true) { |
shindo | 0:e0c9a84c55c9 | 40 | int n = client.receive(buffer, sizeof(buffer)); |
shindo | 2:c1d4ea63ab89 | 41 | int mode = (buffer[0] - 'A'); |
shindo | 0:e0c9a84c55c9 | 42 | if (n > 0) { |
shindo | 2:c1d4ea63ab89 | 43 | int target = (buffer[1] - '0') * 100 + (buffer[2] - '0') * 10 + (buffer[3] - '0'); |
shindo | 1:95407c4ef69e | 44 | |
shindo | 2:c1d4ea63ab89 | 45 | switch (mode) { |
shindo | 2:c1d4ea63ab89 | 46 | case 0: |
shindo | 2:c1d4ea63ab89 | 47 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 48 | meter_LED_outside = p; |
shindo | 0:e0c9a84c55c9 | 49 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 50 | } |
shindo | 2:c1d4ea63ab89 | 51 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 52 | meter_LED_inside = p; |
shindo | 0:e0c9a84c55c9 | 53 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 54 | } |
shindo | 2:c1d4ea63ab89 | 55 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 56 | range_LED_3 = p; |
shindo | 0:e0c9a84c55c9 | 57 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 58 | } |
shindo | 2:c1d4ea63ab89 | 59 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 60 | range_LED_2 = p; |
shindo | 0:e0c9a84c55c9 | 61 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 62 | } |
shindo | 2:c1d4ea63ab89 | 63 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 64 | range_LED_1 = p; |
shindo | 0:e0c9a84c55c9 | 65 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 66 | } |
shindo | 2:c1d4ea63ab89 | 67 | for(float p = 0.0f; p < 1.0f; p += 0.02f) { |
shindo | 0:e0c9a84c55c9 | 68 | needle_LED = p; |
shindo | 0:e0c9a84c55c9 | 69 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 70 | } |
shindo | 2:c1d4ea63ab89 | 71 | for(float p = 1.0f; p > 0.0f; p -= 0.02f) { |
shindo | 0:e0c9a84c55c9 | 72 | meter_LED_outside = p; |
shindo | 0:e0c9a84c55c9 | 73 | meter_LED_inside = p; |
shindo | 0:e0c9a84c55c9 | 74 | range_LED_3 = p; |
shindo | 0:e0c9a84c55c9 | 75 | range_LED_2 = p; |
shindo | 0:e0c9a84c55c9 | 76 | range_LED_1 = p; |
shindo | 0:e0c9a84c55c9 | 77 | needle_LED = p; |
shindo | 0:e0c9a84c55c9 | 78 | wait(0.01); |
shindo | 0:e0c9a84c55c9 | 79 | } |
shindo | 0:e0c9a84c55c9 | 80 | signal_LED_L = 1; |
shindo | 0:e0c9a84c55c9 | 81 | signal_LED_R = 1; |
shindo | 0:e0c9a84c55c9 | 82 | wait (0.5); |
shindo | 0:e0c9a84c55c9 | 83 | signal_LED_L = 0; |
shindo | 0:e0c9a84c55c9 | 84 | signal_LED_R = 0; |
shindo | 0:e0c9a84c55c9 | 85 | wait (0.5); |
shindo | 2:c1d4ea63ab89 | 86 | signal_LED_L = 1; |
shindo | 2:c1d4ea63ab89 | 87 | signal_LED_R = 1; |
shindo | 2:c1d4ea63ab89 | 88 | wait (0.5); |
shindo | 2:c1d4ea63ab89 | 89 | signal_LED_L = 0; |
shindo | 2:c1d4ea63ab89 | 90 | signal_LED_R = 0; |
shindo | 2:c1d4ea63ab89 | 91 | wait (0.5); |
shindo | 0:e0c9a84c55c9 | 92 | |
shindo | 0:e0c9a84c55c9 | 93 | for(float p = 0.0f; p < 0.2f; p += 0.01f) { |
shindo | 0:e0c9a84c55c9 | 94 | meter_LED_outside = p; |
shindo | 0:e0c9a84c55c9 | 95 | meter_LED_inside = p; |
shindo | 0:e0c9a84c55c9 | 96 | // range_LED_3 = p; |
shindo | 0:e0c9a84c55c9 | 97 | range_LED_2 = p; |
shindo | 0:e0c9a84c55c9 | 98 | //range_LED_1 = p; |
shindo | 0:e0c9a84c55c9 | 99 | needle_LED = (p + 0.8); |
shindo | 0:e0c9a84c55c9 | 100 | wait(0.05); |
shindo | 0:e0c9a84c55c9 | 101 | } |
shindo | 1:95407c4ef69e | 102 | digitalclock = 1; |
shindo | 2:c1d4ea63ab89 | 103 | break; |
shindo | 2:c1d4ea63ab89 | 104 | |
shindo | 2:c1d4ea63ab89 | 105 | case 1: |
shindo | 2:c1d4ea63ab89 | 106 | digitalclock = 0; |
shindo | 2:c1d4ea63ab89 | 107 | digitalclock_colon = 0; |
shindo | 2:c1d4ea63ab89 | 108 | for(float p = 0.8f; p > 0.0f; p -= 0.01f) { |
shindo | 2:c1d4ea63ab89 | 109 | meter_LED_outside = p; |
shindo | 2:c1d4ea63ab89 | 110 | meter_LED_inside = p; |
shindo | 2:c1d4ea63ab89 | 111 | range_LED_3 = p; |
shindo | 2:c1d4ea63ab89 | 112 | range_LED_2 = p; |
shindo | 2:c1d4ea63ab89 | 113 | range_LED_1 = p; |
shindo | 2:c1d4ea63ab89 | 114 | needle_LED = p; |
shindo | 2:c1d4ea63ab89 | 115 | wait(0.01); |
shindo | 2:c1d4ea63ab89 | 116 | } |
shindo | 2:c1d4ea63ab89 | 117 | break; |
shindo | 2:c1d4ea63ab89 | 118 | } |
shindo | 2:c1d4ea63ab89 | 119 | if (buffer[0] == 'F') { |
shindo | 1:95407c4ef69e | 120 | meter_LED_outside = (target / 10.0)-0.2; |
shindo | 1:95407c4ef69e | 121 | } else if (buffer[0] == 'G') { |
shindo | 1:95407c4ef69e | 122 | meter_LED_inside = (target / 10.0)-0.2; |
shindo | 1:95407c4ef69e | 123 | } |
shindo | 2:c1d4ea63ab89 | 124 | } |
shindo | 2:c1d4ea63ab89 | 125 | digitalclock_colon = 1; |
shindo | 2:c1d4ea63ab89 | 126 | wait (0.5); |
shindo | 2:c1d4ea63ab89 | 127 | digitalclock_colon = 0; |
shindo | 2:c1d4ea63ab89 | 128 | //wait (0.25); |
shindo | 2:c1d4ea63ab89 | 129 | } |
shindo | 0:e0c9a84c55c9 | 130 | |
shindo | 0:e0c9a84c55c9 | 131 | } |
shindo | 1:95407c4ef69e | 132 | } |
shindo | 1:95407c4ef69e | 133 | |
shindo | 1:95407c4ef69e | 134 |