Lab02-1
Dependencies: mbed
main.cpp@0:5c28f597bf8f, 2015-10-13 (annotated)
- Committer:
- kantapon501
- Date:
- Tue Oct 13 07:38:48 2015 +0000
- Revision:
- 0:5c28f597bf8f
Lab02-1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kantapon501 | 0:5c28f597bf8f | 1 | #include "mbed.h" |
kantapon501 | 0:5c28f597bf8f | 2 | |
kantapon501 | 0:5c28f597bf8f | 3 | DigitalOut Out1(D13); |
kantapon501 | 0:5c28f597bf8f | 4 | DigitalOut Out2(D12); |
kantapon501 | 0:5c28f597bf8f | 5 | DigitalOut Out3(D11); |
kantapon501 | 0:5c28f597bf8f | 6 | DigitalOut Out4(D10); |
kantapon501 | 0:5c28f597bf8f | 7 | DigitalOut Out5(D9); |
kantapon501 | 0:5c28f597bf8f | 8 | DigitalOut Out6(D8); |
kantapon501 | 0:5c28f597bf8f | 9 | DigitalOut Out7(D7); |
kantapon501 | 0:5c28f597bf8f | 10 | DigitalOut Out8(D6); |
kantapon501 | 0:5c28f597bf8f | 11 | AnalogIn Anain(A1); |
kantapon501 | 0:5c28f597bf8f | 12 | |
kantapon501 | 0:5c28f597bf8f | 13 | int main() |
kantapon501 | 0:5c28f597bf8f | 14 | { |
kantapon501 | 0:5c28f597bf8f | 15 | while(1) |
kantapon501 | 0:5c28f597bf8f | 16 | { |
kantapon501 | 0:5c28f597bf8f | 17 | double Value = Anain.read(); |
kantapon501 | 0:5c28f597bf8f | 18 | if(Value <0.0825) |
kantapon501 | 0:5c28f597bf8f | 19 | { |
kantapon501 | 0:5c28f597bf8f | 20 | Out1 = 0; |
kantapon501 | 0:5c28f597bf8f | 21 | Out2 = 0; |
kantapon501 | 0:5c28f597bf8f | 22 | Out3 = 0; |
kantapon501 | 0:5c28f597bf8f | 23 | Out4 = 0; |
kantapon501 | 0:5c28f597bf8f | 24 | Out5 = 0; |
kantapon501 | 0:5c28f597bf8f | 25 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 26 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 27 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 28 | } |
kantapon501 | 0:5c28f597bf8f | 29 | else if(Value >= 0.0825 && Value < 0.165) |
kantapon501 | 0:5c28f597bf8f | 30 | { |
kantapon501 | 0:5c28f597bf8f | 31 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 32 | Out2 = 0; |
kantapon501 | 0:5c28f597bf8f | 33 | Out3 = 0; |
kantapon501 | 0:5c28f597bf8f | 34 | Out4 = 0; |
kantapon501 | 0:5c28f597bf8f | 35 | Out5 = 0; |
kantapon501 | 0:5c28f597bf8f | 36 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 37 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 38 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 39 | } |
kantapon501 | 0:5c28f597bf8f | 40 | else if(Value >= 0.165 && Value < 0.2475) |
kantapon501 | 0:5c28f597bf8f | 41 | { |
kantapon501 | 0:5c28f597bf8f | 42 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 43 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 44 | Out3 = 0; |
kantapon501 | 0:5c28f597bf8f | 45 | Out4 = 0; |
kantapon501 | 0:5c28f597bf8f | 46 | Out5 = 0; |
kantapon501 | 0:5c28f597bf8f | 47 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 48 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 49 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 50 | } |
kantapon501 | 0:5c28f597bf8f | 51 | else if(Value >= 0.2475 && Value < 0.33) |
kantapon501 | 0:5c28f597bf8f | 52 | { |
kantapon501 | 0:5c28f597bf8f | 53 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 54 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 55 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 56 | Out4 = 0; |
kantapon501 | 0:5c28f597bf8f | 57 | Out5 = 0; |
kantapon501 | 0:5c28f597bf8f | 58 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 59 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 60 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 61 | } |
kantapon501 | 0:5c28f597bf8f | 62 | else if(Value >= 0.33 && Value < 0.4125) |
kantapon501 | 0:5c28f597bf8f | 63 | { |
kantapon501 | 0:5c28f597bf8f | 64 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 65 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 66 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 67 | Out4 = 1; |
kantapon501 | 0:5c28f597bf8f | 68 | Out5 = 0; |
kantapon501 | 0:5c28f597bf8f | 69 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 70 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 71 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 72 | } |
kantapon501 | 0:5c28f597bf8f | 73 | else if(Value >= 0.4125 && Value < 0.495) |
kantapon501 | 0:5c28f597bf8f | 74 | { |
kantapon501 | 0:5c28f597bf8f | 75 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 76 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 77 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 78 | Out4 = 1; |
kantapon501 | 0:5c28f597bf8f | 79 | Out5 = 1; |
kantapon501 | 0:5c28f597bf8f | 80 | Out6 = 0; |
kantapon501 | 0:5c28f597bf8f | 81 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 82 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 83 | } |
kantapon501 | 0:5c28f597bf8f | 84 | else if(Value >= 0.495 && Value < 0.5775) |
kantapon501 | 0:5c28f597bf8f | 85 | { |
kantapon501 | 0:5c28f597bf8f | 86 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 87 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 88 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 89 | Out4 = 1; |
kantapon501 | 0:5c28f597bf8f | 90 | Out5 = 1; |
kantapon501 | 0:5c28f597bf8f | 91 | Out6 = 1; |
kantapon501 | 0:5c28f597bf8f | 92 | Out7 = 0; |
kantapon501 | 0:5c28f597bf8f | 93 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 94 | } |
kantapon501 | 0:5c28f597bf8f | 95 | else if(Value >= 0.5775 && Value < 0.66) |
kantapon501 | 0:5c28f597bf8f | 96 | { |
kantapon501 | 0:5c28f597bf8f | 97 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 98 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 99 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 100 | Out4 = 1; |
kantapon501 | 0:5c28f597bf8f | 101 | Out5 = 1; |
kantapon501 | 0:5c28f597bf8f | 102 | Out6 = 1; |
kantapon501 | 0:5c28f597bf8f | 103 | Out7 = 1; |
kantapon501 | 0:5c28f597bf8f | 104 | Out8 = 0; |
kantapon501 | 0:5c28f597bf8f | 105 | } |
kantapon501 | 0:5c28f597bf8f | 106 | else if(Value >= 0.66) |
kantapon501 | 0:5c28f597bf8f | 107 | { |
kantapon501 | 0:5c28f597bf8f | 108 | Out1 = 1; |
kantapon501 | 0:5c28f597bf8f | 109 | Out2 = 1; |
kantapon501 | 0:5c28f597bf8f | 110 | Out3 = 1; |
kantapon501 | 0:5c28f597bf8f | 111 | Out4 = 1; |
kantapon501 | 0:5c28f597bf8f | 112 | Out5 = 1; |
kantapon501 | 0:5c28f597bf8f | 113 | Out6 = 1; |
kantapon501 | 0:5c28f597bf8f | 114 | Out7 = 1; |
kantapon501 | 0:5c28f597bf8f | 115 | Out8 = 1; |
kantapon501 | 0:5c28f597bf8f | 116 | } |
kantapon501 | 0:5c28f597bf8f | 117 | } |
kantapon501 | 0:5c28f597bf8f | 118 | |
kantapon501 | 0:5c28f597bf8f | 119 | |
kantapon501 | 0:5c28f597bf8f | 120 | } |
kantapon501 | 0:5c28f597bf8f | 121 |