-
Dependencies: mbed
main.cpp@0:bb3bdea2f73b, 2015-11-17 (annotated)
- Committer:
- Pumipachpro
- Date:
- Tue Nov 17 02:51:37 2015 +0000
- Revision:
- 0:bb3bdea2f73b
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pumipachpro | 0:bb3bdea2f73b | 1 | #include "mbed.h" |
Pumipachpro | 0:bb3bdea2f73b | 2 | |
Pumipachpro | 0:bb3bdea2f73b | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
Pumipachpro | 0:bb3bdea2f73b | 4 | |
Pumipachpro | 0:bb3bdea2f73b | 5 | DigitalOut led0(D2); |
Pumipachpro | 0:bb3bdea2f73b | 6 | DigitalOut led1(D3); |
Pumipachpro | 0:bb3bdea2f73b | 7 | DigitalOut led2(D4); |
Pumipachpro | 0:bb3bdea2f73b | 8 | DigitalOut led3(D5); |
Pumipachpro | 0:bb3bdea2f73b | 9 | DigitalOut led4(D6); |
Pumipachpro | 0:bb3bdea2f73b | 10 | DigitalOut led5(D7); |
Pumipachpro | 0:bb3bdea2f73b | 11 | DigitalOut led6(D8); |
Pumipachpro | 0:bb3bdea2f73b | 12 | DigitalOut led7(D9); |
Pumipachpro | 0:bb3bdea2f73b | 13 | |
Pumipachpro | 0:bb3bdea2f73b | 14 | int main() |
Pumipachpro | 0:bb3bdea2f73b | 15 | { |
Pumipachpro | 0:bb3bdea2f73b | 16 | |
Pumipachpro | 0:bb3bdea2f73b | 17 | uint8_t state_menu=0; |
Pumipachpro | 0:bb3bdea2f73b | 18 | uint8_t state_show=0; |
Pumipachpro | 0:bb3bdea2f73b | 19 | uint8_t state_exit =0; |
Pumipachpro | 0:bb3bdea2f73b | 20 | uint8_t data; |
Pumipachpro | 0:bb3bdea2f73b | 21 | |
Pumipachpro | 0:bb3bdea2f73b | 22 | led0=0; |
Pumipachpro | 0:bb3bdea2f73b | 23 | led1=0; |
Pumipachpro | 0:bb3bdea2f73b | 24 | led2=0; |
Pumipachpro | 0:bb3bdea2f73b | 25 | led3=0; |
Pumipachpro | 0:bb3bdea2f73b | 26 | led4=0; |
Pumipachpro | 0:bb3bdea2f73b | 27 | led5=0; |
Pumipachpro | 0:bb3bdea2f73b | 28 | led6=0; |
Pumipachpro | 0:bb3bdea2f73b | 29 | led7=0; |
Pumipachpro | 0:bb3bdea2f73b | 30 | |
Pumipachpro | 0:bb3bdea2f73b | 31 | while(1) { |
Pumipachpro | 0:bb3bdea2f73b | 32 | if(state_show == 0) { |
Pumipachpro | 0:bb3bdea2f73b | 33 | pc.printf("Menu\n"); |
Pumipachpro | 0:bb3bdea2f73b | 34 | pc.printf("1.Play with LED\n"); |
Pumipachpro | 0:bb3bdea2f73b | 35 | pc.printf("2.Check Statement\n"); |
Pumipachpro | 0:bb3bdea2f73b | 36 | state_show =1; |
Pumipachpro | 0:bb3bdea2f73b | 37 | } |
Pumipachpro | 0:bb3bdea2f73b | 38 | if(pc.readable()) { |
Pumipachpro | 0:bb3bdea2f73b | 39 | data = pc.getc(); |
Pumipachpro | 0:bb3bdea2f73b | 40 | pc.printf("\n"); |
Pumipachpro | 0:bb3bdea2f73b | 41 | state_show =0; |
Pumipachpro | 0:bb3bdea2f73b | 42 | state_exit =0; |
Pumipachpro | 0:bb3bdea2f73b | 43 | |
Pumipachpro | 0:bb3bdea2f73b | 44 | switch(data) { |
Pumipachpro | 0:bb3bdea2f73b | 45 | case '1': |
Pumipachpro | 0:bb3bdea2f73b | 46 | do { |
Pumipachpro | 0:bb3bdea2f73b | 47 | if(state_menu == 0) { |
Pumipachpro | 0:bb3bdea2f73b | 48 | pc.printf("Select Pattern\n"); |
Pumipachpro | 0:bb3bdea2f73b | 49 | pc.printf("a.LED No.1\n"); |
Pumipachpro | 0:bb3bdea2f73b | 50 | pc.printf("d.LED No.2\n"); |
Pumipachpro | 0:bb3bdea2f73b | 51 | pc.printf("s.Exit\n"); |
Pumipachpro | 0:bb3bdea2f73b | 52 | state_menu = 1; |
Pumipachpro | 0:bb3bdea2f73b | 53 | } |
Pumipachpro | 0:bb3bdea2f73b | 54 | if(pc.readable()) { |
Pumipachpro | 0:bb3bdea2f73b | 55 | data = pc.getc(); |
Pumipachpro | 0:bb3bdea2f73b | 56 | pc.printf("\n"); |
Pumipachpro | 0:bb3bdea2f73b | 57 | state_menu=0; |
Pumipachpro | 0:bb3bdea2f73b | 58 | |
Pumipachpro | 0:bb3bdea2f73b | 59 | switch(data) { |
Pumipachpro | 0:bb3bdea2f73b | 60 | |
Pumipachpro | 0:bb3bdea2f73b | 61 | case 'a': |
Pumipachpro | 0:bb3bdea2f73b | 62 | while(1) { |
Pumipachpro | 0:bb3bdea2f73b | 63 | if(pc.readable()) { |
Pumipachpro | 0:bb3bdea2f73b | 64 | data = pc.getc(); |
Pumipachpro | 0:bb3bdea2f73b | 65 | } else if(data=='a') { |
Pumipachpro | 0:bb3bdea2f73b | 66 | led0=1; |
Pumipachpro | 0:bb3bdea2f73b | 67 | led1=0; |
Pumipachpro | 0:bb3bdea2f73b | 68 | led2=1; |
Pumipachpro | 0:bb3bdea2f73b | 69 | led3=0; |
Pumipachpro | 0:bb3bdea2f73b | 70 | led4=1; |
Pumipachpro | 0:bb3bdea2f73b | 71 | led5=0; |
Pumipachpro | 0:bb3bdea2f73b | 72 | led6=1; |
Pumipachpro | 0:bb3bdea2f73b | 73 | led7=0; |
Pumipachpro | 0:bb3bdea2f73b | 74 | wait(0.3); |
Pumipachpro | 0:bb3bdea2f73b | 75 | led0=0; |
Pumipachpro | 0:bb3bdea2f73b | 76 | led1=1; |
Pumipachpro | 0:bb3bdea2f73b | 77 | led2=0; |
Pumipachpro | 0:bb3bdea2f73b | 78 | led3=1; |
Pumipachpro | 0:bb3bdea2f73b | 79 | led4=0; |
Pumipachpro | 0:bb3bdea2f73b | 80 | led5=1; |
Pumipachpro | 0:bb3bdea2f73b | 81 | led6=0; |
Pumipachpro | 0:bb3bdea2f73b | 82 | led7=1; |
Pumipachpro | 0:bb3bdea2f73b | 83 | wait(0.3); |
Pumipachpro | 0:bb3bdea2f73b | 84 | } else if(data != 'a') { |
Pumipachpro | 0:bb3bdea2f73b | 85 | break; |
Pumipachpro | 0:bb3bdea2f73b | 86 | } |
Pumipachpro | 0:bb3bdea2f73b | 87 | } |
Pumipachpro | 0:bb3bdea2f73b | 88 | |
Pumipachpro | 0:bb3bdea2f73b | 89 | case 's': |
Pumipachpro | 0:bb3bdea2f73b | 90 | led0 =0; |
Pumipachpro | 0:bb3bdea2f73b | 91 | |
Pumipachpro | 0:bb3bdea2f73b | 92 | break; |
Pumipachpro | 0:bb3bdea2f73b | 93 | |
Pumipachpro | 0:bb3bdea2f73b | 94 | case 'x': |
Pumipachpro | 0:bb3bdea2f73b | 95 | state_exit =1; |
Pumipachpro | 0:bb3bdea2f73b | 96 | |
Pumipachpro | 0:bb3bdea2f73b | 97 | break; |
Pumipachpro | 0:bb3bdea2f73b | 98 | |
Pumipachpro | 0:bb3bdea2f73b | 99 | default: |
Pumipachpro | 0:bb3bdea2f73b | 100 | pc.printf("plz select a or s\n"); |
Pumipachpro | 0:bb3bdea2f73b | 101 | pc.printf("\n\n"); |
Pumipachpro | 0:bb3bdea2f73b | 102 | break; |
Pumipachpro | 0:bb3bdea2f73b | 103 | |
Pumipachpro | 0:bb3bdea2f73b | 104 | } |
Pumipachpro | 0:bb3bdea2f73b | 105 | } |
Pumipachpro | 0:bb3bdea2f73b | 106 | |
Pumipachpro | 0:bb3bdea2f73b | 107 | |
Pumipachpro | 0:bb3bdea2f73b | 108 | |
Pumipachpro | 0:bb3bdea2f73b | 109 | } while(state_exit ==0); |
Pumipachpro | 0:bb3bdea2f73b | 110 | pc.printf("\n\n"); |
Pumipachpro | 0:bb3bdea2f73b | 111 | break; |
Pumipachpro | 0:bb3bdea2f73b | 112 | |
Pumipachpro | 0:bb3bdea2f73b | 113 | case '2': |
Pumipachpro | 0:bb3bdea2f73b | 114 | |
Pumipachpro | 0:bb3bdea2f73b | 115 | do { |
Pumipachpro | 0:bb3bdea2f73b | 116 | if(state_menu == 0) { |
Pumipachpro | 0:bb3bdea2f73b | 117 | pc.printf("LED Test\n"); |
Pumipachpro | 0:bb3bdea2f73b | 118 | pc.printf("a.Menu 2 TEST\n"); |
Pumipachpro | 0:bb3bdea2f73b | 119 | pc.printf("s.Run\n"); |
Pumipachpro | 0:bb3bdea2f73b | 120 | pc.printf("x.Exit\n"); |
Pumipachpro | 0:bb3bdea2f73b | 121 | state_menu = 1; |
Pumipachpro | 0:bb3bdea2f73b | 122 | } |
Pumipachpro | 0:bb3bdea2f73b | 123 | if(pc.readable()) { |
Pumipachpro | 0:bb3bdea2f73b | 124 | data = pc.getc(); |
Pumipachpro | 0:bb3bdea2f73b | 125 | pc.printf("\n"); |
Pumipachpro | 0:bb3bdea2f73b | 126 | state_menu=0; |
Pumipachpro | 0:bb3bdea2f73b | 127 | |
Pumipachpro | 0:bb3bdea2f73b | 128 | switch(data) { |
Pumipachpro | 0:bb3bdea2f73b | 129 | |
Pumipachpro | 0:bb3bdea2f73b | 130 | case 'a': |
Pumipachpro | 0:bb3bdea2f73b | 131 | pc.printf("Menu 2 TEST\n"); |
Pumipachpro | 0:bb3bdea2f73b | 132 | |
Pumipachpro | 0:bb3bdea2f73b | 133 | break; |
Pumipachpro | 0:bb3bdea2f73b | 134 | |
Pumipachpro | 0:bb3bdea2f73b | 135 | case 's': |
Pumipachpro | 0:bb3bdea2f73b | 136 | pc.printf("Run\n"); |
Pumipachpro | 0:bb3bdea2f73b | 137 | |
Pumipachpro | 0:bb3bdea2f73b | 138 | break; |
Pumipachpro | 0:bb3bdea2f73b | 139 | |
Pumipachpro | 0:bb3bdea2f73b | 140 | case 'x': |
Pumipachpro | 0:bb3bdea2f73b | 141 | state_exit =1; |
Pumipachpro | 0:bb3bdea2f73b | 142 | |
Pumipachpro | 0:bb3bdea2f73b | 143 | |
Pumipachpro | 0:bb3bdea2f73b | 144 | break; |
Pumipachpro | 0:bb3bdea2f73b | 145 | |
Pumipachpro | 0:bb3bdea2f73b | 146 | default: |
Pumipachpro | 0:bb3bdea2f73b | 147 | pc.printf("plz select a or s\n"); |
Pumipachpro | 0:bb3bdea2f73b | 148 | pc.printf("\n\n"); |
Pumipachpro | 0:bb3bdea2f73b | 149 | break; |
Pumipachpro | 0:bb3bdea2f73b | 150 | |
Pumipachpro | 0:bb3bdea2f73b | 151 | } |
Pumipachpro | 0:bb3bdea2f73b | 152 | } |
Pumipachpro | 0:bb3bdea2f73b | 153 | |
Pumipachpro | 0:bb3bdea2f73b | 154 | |
Pumipachpro | 0:bb3bdea2f73b | 155 | |
Pumipachpro | 0:bb3bdea2f73b | 156 | } while(state_exit ==0); |
Pumipachpro | 0:bb3bdea2f73b | 157 | pc.printf("\n\n"); |
Pumipachpro | 0:bb3bdea2f73b | 158 | break; |
Pumipachpro | 0:bb3bdea2f73b | 159 | |
Pumipachpro | 0:bb3bdea2f73b | 160 | |
Pumipachpro | 0:bb3bdea2f73b | 161 | case 0x00: |
Pumipachpro | 0:bb3bdea2f73b | 162 | |
Pumipachpro | 0:bb3bdea2f73b | 163 | break; |
Pumipachpro | 0:bb3bdea2f73b | 164 | |
Pumipachpro | 0:bb3bdea2f73b | 165 | default: |
Pumipachpro | 0:bb3bdea2f73b | 166 | pc.printf("plz select 1 or 2 only\n"); |
Pumipachpro | 0:bb3bdea2f73b | 167 | pc.printf("\n\n"); |
Pumipachpro | 0:bb3bdea2f73b | 168 | break; |
Pumipachpro | 0:bb3bdea2f73b | 169 | } |
Pumipachpro | 0:bb3bdea2f73b | 170 | } |
Pumipachpro | 0:bb3bdea2f73b | 171 | |
Pumipachpro | 0:bb3bdea2f73b | 172 | |
Pumipachpro | 0:bb3bdea2f73b | 173 | |
Pumipachpro | 0:bb3bdea2f73b | 174 | |
Pumipachpro | 0:bb3bdea2f73b | 175 | |
Pumipachpro | 0:bb3bdea2f73b | 176 | |
Pumipachpro | 0:bb3bdea2f73b | 177 | } |
Pumipachpro | 0:bb3bdea2f73b | 178 | } |