Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:48d05483fffc, 2019-04-11 (annotated)
- Committer:
- mksaga
- Date:
- Thu Apr 11 22:09:50 2019 +0000
- Revision:
- 1:48d05483fffc
- Parent:
- 0:572230252a64
- Child:
- 2:66ab94f69a1a
Adds baseline functionality: five sensors, distinguishes back/side/absent
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fatiho | 0:572230252a64 | 1 | #include "mbed.h" |
fatiho | 0:572230252a64 | 2 | |
fatiho | 0:572230252a64 | 3 | DigitalOut myled(LED1); |
fatiho | 0:572230252a64 | 4 | DigitalOut myled2(LED2); |
fatiho | 0:572230252a64 | 5 | AnalogIn senseMe1(p20); |
mksaga | 1:48d05483fffc | 6 | |
mksaga | 1:48d05483fffc | 7 | AnalogIn sense0(p16); |
mksaga | 1:48d05483fffc | 8 | AnalogIn sense1(p17); |
mksaga | 1:48d05483fffc | 9 | AnalogIn sense2(p18); |
mksaga | 1:48d05483fffc | 10 | AnalogIn sense3(p19); |
mksaga | 1:48d05483fffc | 11 | AnalogIn sense4(p20); |
fatiho | 0:572230252a64 | 12 | |
fatiho | 0:572230252a64 | 13 | int main() { |
fatiho | 0:572230252a64 | 14 | while(1) { |
fatiho | 0:572230252a64 | 15 | myled = 1; |
fatiho | 0:572230252a64 | 16 | wait(0.2); |
fatiho | 0:572230252a64 | 17 | myled = 0; |
fatiho | 0:572230252a64 | 18 | myled2 = 1; |
fatiho | 0:572230252a64 | 19 | wait(0.2); |
fatiho | 0:572230252a64 | 20 | myled2 = 0; |
mksaga | 1:48d05483fffc | 21 | float se0 = sense0.read(); |
mksaga | 1:48d05483fffc | 22 | float se1 = sense1.read(); |
mksaga | 1:48d05483fffc | 23 | float se2 = sense2.read(); |
mksaga | 1:48d05483fffc | 24 | float se3 = sense3.read(); |
mksaga | 1:48d05483fffc | 25 | float se4 = sense4.read(); |
mksaga | 1:48d05483fffc | 26 | printf("%1.2f", se0); |
mksaga | 1:48d05483fffc | 27 | printf(" | %1.2f", se1); |
mksaga | 1:48d05483fffc | 28 | printf(" | %1.2f", se2); |
mksaga | 1:48d05483fffc | 29 | printf(" | %1.2f", se3); |
mksaga | 1:48d05483fffc | 30 | printf(" | %1.2f", se4); |
mksaga | 1:48d05483fffc | 31 | float sum = se0 + se1 + se2 + se3 + se4; |
mksaga | 1:48d05483fffc | 32 | if (sum > 4.94) { |
mksaga | 1:48d05483fffc | 33 | printf("|bacK\n"); |
mksaga | 1:48d05483fffc | 34 | } else if (sum > 1.0) { |
mksaga | 1:48d05483fffc | 35 | printf("|sIDE\n"); |
mksaga | 1:48d05483fffc | 36 | } else { |
mksaga | 1:48d05483fffc | 37 | printf("|no\n"); |
mksaga | 1:48d05483fffc | 38 | } |
mksaga | 1:48d05483fffc | 39 | wait(1); |
fatiho | 0:572230252a64 | 40 | } |
fatiho | 0:572230252a64 | 41 | } |