nicolás rodríguez
/
adc
Conversor ADC con leds
main.cpp@0:75d0e094aebd, 2017-08-19 (annotated)
- Committer:
- nikor97r
- Date:
- Sat Aug 19 20:22:42 2017 +0000
- Revision:
- 0:75d0e094aebd
Conversor ADC con leds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikor97r | 0:75d0e094aebd | 1 | #include "mbed.h" |
nikor97r | 0:75d0e094aebd | 2 | AnalogIn adc(A1); |
nikor97r | 0:75d0e094aebd | 3 | DigitalOut led1(D13); |
nikor97r | 0:75d0e094aebd | 4 | DigitalOut led2(D2); |
nikor97r | 0:75d0e094aebd | 5 | DigitalOut led3(D3); |
nikor97r | 0:75d0e094aebd | 6 | DigitalOut led4(D4); |
nikor97r | 0:75d0e094aebd | 7 | DigitalOut led5(D5); |
nikor97r | 0:75d0e094aebd | 8 | DigitalOut led6(D6); |
nikor97r | 0:75d0e094aebd | 9 | DigitalOut led7(D7); |
nikor97r | 0:75d0e094aebd | 10 | DigitalOut led8(D8); |
nikor97r | 0:75d0e094aebd | 11 | DigitalOut led9(D9); |
nikor97r | 0:75d0e094aebd | 12 | DigitalOut led10(D10); |
nikor97r | 0:75d0e094aebd | 13 | DigitalOut led11(D11); |
nikor97r | 0:75d0e094aebd | 14 | DigitalOut led12(D12); |
nikor97r | 0:75d0e094aebd | 15 | float conversion; |
nikor97r | 0:75d0e094aebd | 16 | float conversion1; |
nikor97r | 0:75d0e094aebd | 17 | int main() |
nikor97r | 0:75d0e094aebd | 18 | { |
nikor97r | 0:75d0e094aebd | 19 | led1=1; |
nikor97r | 0:75d0e094aebd | 20 | led2=0; |
nikor97r | 0:75d0e094aebd | 21 | led3=0; |
nikor97r | 0:75d0e094aebd | 22 | led4=0; |
nikor97r | 0:75d0e094aebd | 23 | led5=0; |
nikor97r | 0:75d0e094aebd | 24 | led6=0; |
nikor97r | 0:75d0e094aebd | 25 | led7=0; |
nikor97r | 0:75d0e094aebd | 26 | led8=0; |
nikor97r | 0:75d0e094aebd | 27 | led9=0; |
nikor97r | 0:75d0e094aebd | 28 | led10=0; |
nikor97r | 0:75d0e094aebd | 29 | led11=0; |
nikor97r | 0:75d0e094aebd | 30 | led12=0; |
nikor97r | 0:75d0e094aebd | 31 | while(1) |
nikor97r | 0:75d0e094aebd | 32 | { |
nikor97r | 0:75d0e094aebd | 33 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 34 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 35 | |
nikor97r | 0:75d0e094aebd | 36 | while(conversion1 <=0.275 && conversion1 >0) |
nikor97r | 0:75d0e094aebd | 37 | { |
nikor97r | 0:75d0e094aebd | 38 | |
nikor97r | 0:75d0e094aebd | 39 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 40 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 41 | led1=1; |
nikor97r | 0:75d0e094aebd | 42 | |
nikor97r | 0:75d0e094aebd | 43 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 44 | } |
nikor97r | 0:75d0e094aebd | 45 | led1=0; |
nikor97r | 0:75d0e094aebd | 46 | |
nikor97r | 0:75d0e094aebd | 47 | while(conversion1 <=(0.275*2) && conversion1 >0.275) |
nikor97r | 0:75d0e094aebd | 48 | { |
nikor97r | 0:75d0e094aebd | 49 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 50 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 51 | led2=1; |
nikor97r | 0:75d0e094aebd | 52 | led1=1; |
nikor97r | 0:75d0e094aebd | 53 | |
nikor97r | 0:75d0e094aebd | 54 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 55 | } |
nikor97r | 0:75d0e094aebd | 56 | led2=0; |
nikor97r | 0:75d0e094aebd | 57 | while(conversion1 <=(0.275*3) && conversion1 >(0.275*2)) |
nikor97r | 0:75d0e094aebd | 58 | { |
nikor97r | 0:75d0e094aebd | 59 | |
nikor97r | 0:75d0e094aebd | 60 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 61 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 62 | led3=1; |
nikor97r | 0:75d0e094aebd | 63 | led1=1; |
nikor97r | 0:75d0e094aebd | 64 | led2=1; |
nikor97r | 0:75d0e094aebd | 65 | |
nikor97r | 0:75d0e094aebd | 66 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 67 | } |
nikor97r | 0:75d0e094aebd | 68 | led3=0; |
nikor97r | 0:75d0e094aebd | 69 | while(conversion1 <=(0.275*4) && conversion1 >(0.275*3)) |
nikor97r | 0:75d0e094aebd | 70 | { |
nikor97r | 0:75d0e094aebd | 71 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 72 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 73 | led4=1; |
nikor97r | 0:75d0e094aebd | 74 | led3=1; |
nikor97r | 0:75d0e094aebd | 75 | led2=1; |
nikor97r | 0:75d0e094aebd | 76 | led1=1; |
nikor97r | 0:75d0e094aebd | 77 | |
nikor97r | 0:75d0e094aebd | 78 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 79 | } |
nikor97r | 0:75d0e094aebd | 80 | led4=0; |
nikor97r | 0:75d0e094aebd | 81 | while(conversion1 <=(0.275*5) && conversion1 >(0.275*4)) |
nikor97r | 0:75d0e094aebd | 82 | { |
nikor97r | 0:75d0e094aebd | 83 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 84 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 85 | led5=1; |
nikor97r | 0:75d0e094aebd | 86 | led4=1; |
nikor97r | 0:75d0e094aebd | 87 | led3=1; |
nikor97r | 0:75d0e094aebd | 88 | led2=1; |
nikor97r | 0:75d0e094aebd | 89 | led1=1; |
nikor97r | 0:75d0e094aebd | 90 | |
nikor97r | 0:75d0e094aebd | 91 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 92 | } |
nikor97r | 0:75d0e094aebd | 93 | led5=0; |
nikor97r | 0:75d0e094aebd | 94 | while(conversion1 <=0.275*6 && conversion1 >0.275*5) |
nikor97r | 0:75d0e094aebd | 95 | { |
nikor97r | 0:75d0e094aebd | 96 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 97 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 98 | led6=1; |
nikor97r | 0:75d0e094aebd | 99 | led5=1; |
nikor97r | 0:75d0e094aebd | 100 | led4=1; |
nikor97r | 0:75d0e094aebd | 101 | led3=1; |
nikor97r | 0:75d0e094aebd | 102 | led2=1; |
nikor97r | 0:75d0e094aebd | 103 | led1=1; |
nikor97r | 0:75d0e094aebd | 104 | |
nikor97r | 0:75d0e094aebd | 105 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 106 | } |
nikor97r | 0:75d0e094aebd | 107 | led6=0; |
nikor97r | 0:75d0e094aebd | 108 | while(conversion1 <=(0.275*7) && conversion1 >(0.275*6)) |
nikor97r | 0:75d0e094aebd | 109 | { |
nikor97r | 0:75d0e094aebd | 110 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 111 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 112 | led7=1; |
nikor97r | 0:75d0e094aebd | 113 | led6=1; |
nikor97r | 0:75d0e094aebd | 114 | led5=1; |
nikor97r | 0:75d0e094aebd | 115 | led4=1; |
nikor97r | 0:75d0e094aebd | 116 | led3=1; |
nikor97r | 0:75d0e094aebd | 117 | led2=1; |
nikor97r | 0:75d0e094aebd | 118 | led1=1; |
nikor97r | 0:75d0e094aebd | 119 | |
nikor97r | 0:75d0e094aebd | 120 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 121 | } |
nikor97r | 0:75d0e094aebd | 122 | led7=0; |
nikor97r | 0:75d0e094aebd | 123 | |
nikor97r | 0:75d0e094aebd | 124 | while(conversion1 <=(0.275*8) && conversion1 >(0.275*7)) |
nikor97r | 0:75d0e094aebd | 125 | { |
nikor97r | 0:75d0e094aebd | 126 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 127 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 128 | led8=1; |
nikor97r | 0:75d0e094aebd | 129 | led7=1; |
nikor97r | 0:75d0e094aebd | 130 | led6=1; |
nikor97r | 0:75d0e094aebd | 131 | led5=1; |
nikor97r | 0:75d0e094aebd | 132 | led4=1; |
nikor97r | 0:75d0e094aebd | 133 | led3=1; |
nikor97r | 0:75d0e094aebd | 134 | led2=1; |
nikor97r | 0:75d0e094aebd | 135 | led1=1; |
nikor97r | 0:75d0e094aebd | 136 | |
nikor97r | 0:75d0e094aebd | 137 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 138 | } |
nikor97r | 0:75d0e094aebd | 139 | led8=0; |
nikor97r | 0:75d0e094aebd | 140 | |
nikor97r | 0:75d0e094aebd | 141 | while(conversion1 <=(0.275*9) && conversion1 >(0.275*8)) |
nikor97r | 0:75d0e094aebd | 142 | { |
nikor97r | 0:75d0e094aebd | 143 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 144 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 145 | led9=1; |
nikor97r | 0:75d0e094aebd | 146 | led8=1; |
nikor97r | 0:75d0e094aebd | 147 | led7=1; |
nikor97r | 0:75d0e094aebd | 148 | led6=1; |
nikor97r | 0:75d0e094aebd | 149 | led5=1; |
nikor97r | 0:75d0e094aebd | 150 | led4=1; |
nikor97r | 0:75d0e094aebd | 151 | led3=1; |
nikor97r | 0:75d0e094aebd | 152 | led2=1; |
nikor97r | 0:75d0e094aebd | 153 | led1=1; |
nikor97r | 0:75d0e094aebd | 154 | |
nikor97r | 0:75d0e094aebd | 155 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 156 | } |
nikor97r | 0:75d0e094aebd | 157 | led9=0; |
nikor97r | 0:75d0e094aebd | 158 | |
nikor97r | 0:75d0e094aebd | 159 | while(conversion1 <=(0.275*10) && conversion1>(0.275*9)) |
nikor97r | 0:75d0e094aebd | 160 | { |
nikor97r | 0:75d0e094aebd | 161 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 162 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 163 | led10=1; |
nikor97r | 0:75d0e094aebd | 164 | led9=1; |
nikor97r | 0:75d0e094aebd | 165 | led8=1; |
nikor97r | 0:75d0e094aebd | 166 | led7=1; |
nikor97r | 0:75d0e094aebd | 167 | led6=1; |
nikor97r | 0:75d0e094aebd | 168 | led5=1; |
nikor97r | 0:75d0e094aebd | 169 | led4=1; |
nikor97r | 0:75d0e094aebd | 170 | led3=1; |
nikor97r | 0:75d0e094aebd | 171 | led2=1; |
nikor97r | 0:75d0e094aebd | 172 | led1=1; |
nikor97r | 0:75d0e094aebd | 173 | |
nikor97r | 0:75d0e094aebd | 174 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 175 | } |
nikor97r | 0:75d0e094aebd | 176 | led10=0; |
nikor97r | 0:75d0e094aebd | 177 | |
nikor97r | 0:75d0e094aebd | 178 | while(conversion1 <=(0.275*11) && conversion1 >(0.275*10)) |
nikor97r | 0:75d0e094aebd | 179 | { |
nikor97r | 0:75d0e094aebd | 180 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 181 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 182 | led11=1; |
nikor97r | 0:75d0e094aebd | 183 | led10=1; |
nikor97r | 0:75d0e094aebd | 184 | led9=1; |
nikor97r | 0:75d0e094aebd | 185 | led8=1; |
nikor97r | 0:75d0e094aebd | 186 | led7=1; |
nikor97r | 0:75d0e094aebd | 187 | led6=1; |
nikor97r | 0:75d0e094aebd | 188 | led5=1; |
nikor97r | 0:75d0e094aebd | 189 | led4=1; |
nikor97r | 0:75d0e094aebd | 190 | led3=1; |
nikor97r | 0:75d0e094aebd | 191 | led2=1; |
nikor97r | 0:75d0e094aebd | 192 | led1=1; |
nikor97r | 0:75d0e094aebd | 193 | |
nikor97r | 0:75d0e094aebd | 194 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 195 | } |
nikor97r | 0:75d0e094aebd | 196 | led11=0; |
nikor97r | 0:75d0e094aebd | 197 | |
nikor97r | 0:75d0e094aebd | 198 | while(conversion1 <=(0.275*12) && conversion1 >(0.275*11)) |
nikor97r | 0:75d0e094aebd | 199 | { |
nikor97r | 0:75d0e094aebd | 200 | conversion = adc.read_u16(); |
nikor97r | 0:75d0e094aebd | 201 | conversion1 = (conversion*0.00005); |
nikor97r | 0:75d0e094aebd | 202 | led12=1; |
nikor97r | 0:75d0e094aebd | 203 | led11=1; |
nikor97r | 0:75d0e094aebd | 204 | led10=1; |
nikor97r | 0:75d0e094aebd | 205 | led9=1; |
nikor97r | 0:75d0e094aebd | 206 | led8=1; |
nikor97r | 0:75d0e094aebd | 207 | led7=1; |
nikor97r | 0:75d0e094aebd | 208 | led6=1; |
nikor97r | 0:75d0e094aebd | 209 | led5=1; |
nikor97r | 0:75d0e094aebd | 210 | led4=1; |
nikor97r | 0:75d0e094aebd | 211 | led3=1; |
nikor97r | 0:75d0e094aebd | 212 | led2=1; |
nikor97r | 0:75d0e094aebd | 213 | led1=1; |
nikor97r | 0:75d0e094aebd | 214 | |
nikor97r | 0:75d0e094aebd | 215 | |
nikor97r | 0:75d0e094aebd | 216 | wait(0.1); |
nikor97r | 0:75d0e094aebd | 217 | } |
nikor97r | 0:75d0e094aebd | 218 | led12=0; |
nikor97r | 0:75d0e094aebd | 219 | |
nikor97r | 0:75d0e094aebd | 220 | |
nikor97r | 0:75d0e094aebd | 221 | |
nikor97r | 0:75d0e094aebd | 222 | } |
nikor97r | 0:75d0e094aebd | 223 | |
nikor97r | 0:75d0e094aebd | 224 | } |
nikor97r | 0:75d0e094aebd | 225 |