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@0:46b2c955924b, 2018-03-08 (annotated)
- Committer:
- _laurentaylorrr
- Date:
- Thu Mar 08 18:17:55 2018 +0000
- Revision:
- 0:46b2c955924b
- Child:
- 1:279fcab0c394
Just reads phototransistor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
_laurentaylorrr | 0:46b2c955924b | 1 | #include "mbed.h" |
_laurentaylorrr | 0:46b2c955924b | 2 | AnalogIn lightSensor(p20); |
_laurentaylorrr | 0:46b2c955924b | 3 | Serial pc(USBTX,USBRX); |
_laurentaylorrr | 0:46b2c955924b | 4 | int main() { |
_laurentaylorrr | 0:46b2c955924b | 5 | float x; |
_laurentaylorrr | 0:46b2c955924b | 6 | int n = 10; |
_laurentaylorrr | 0:46b2c955924b | 7 | while(1) { |
_laurentaylorrr | 0:46b2c955924b | 8 | // Average n readings of the light sensor |
_laurentaylorrr | 0:46b2c955924b | 9 | x = 0; |
_laurentaylorrr | 0:46b2c955924b | 10 | for (int i = 0; i<n; i++) |
_laurentaylorrr | 0:46b2c955924b | 11 | x = x + lightSensor; |
_laurentaylorrr | 0:46b2c955924b | 12 | x = x/n; |
_laurentaylorrr | 0:46b2c955924b | 13 | pc.printf("%.4f\r\n", x); |
_laurentaylorrr | 0:46b2c955924b | 14 | wait(0.2); |
_laurentaylorrr | 0:46b2c955924b | 15 | } |
_laurentaylorrr | 0:46b2c955924b | 16 | } |