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:279fcab0c394, 2018-03-08 (annotated)
- Committer:
- _laurentaylorrr
- Date:
- Thu Mar 08 18:20:06 2018 +0000
- Revision:
- 1:279fcab0c394
- Parent:
- 0:46b2c955924b
- Child:
- 2:c76b070c2a55
Added red LED
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 | 1:279fcab0c394 | 3 | DigitalOut ledRed(p25); |
_laurentaylorrr | 1:279fcab0c394 | 4 | |
_laurentaylorrr | 0:46b2c955924b | 5 | Serial pc(USBTX,USBRX); |
_laurentaylorrr | 0:46b2c955924b | 6 | int main() { |
_laurentaylorrr | 0:46b2c955924b | 7 | float x; |
_laurentaylorrr | 0:46b2c955924b | 8 | int n = 10; |
_laurentaylorrr | 1:279fcab0c394 | 9 | while(1) { |
_laurentaylorrr | 1:279fcab0c394 | 10 | ledRed = 1; |
_laurentaylorrr | 0:46b2c955924b | 11 | // Average n readings of the light sensor |
_laurentaylorrr | 0:46b2c955924b | 12 | x = 0; |
_laurentaylorrr | 0:46b2c955924b | 13 | for (int i = 0; i<n; i++) |
_laurentaylorrr | 0:46b2c955924b | 14 | x = x + lightSensor; |
_laurentaylorrr | 0:46b2c955924b | 15 | x = x/n; |
_laurentaylorrr | 1:279fcab0c394 | 16 | pc.printf("%.4f\r\n", x); |
_laurentaylorrr | 1:279fcab0c394 | 17 | ledRed = 0; |
_laurentaylorrr | 1:279fcab0c394 | 18 | // Average n readings of the light sensor |
_laurentaylorrr | 1:279fcab0c394 | 19 | x = 0; |
_laurentaylorrr | 1:279fcab0c394 | 20 | for (int i = 0; i<n; i++) |
_laurentaylorrr | 1:279fcab0c394 | 21 | x = x + lightSensor; |
_laurentaylorrr | 1:279fcab0c394 | 22 | x = x/n; |
_laurentaylorrr | 1:279fcab0c394 | 23 | pc.printf("%.4f\r\n", x); |
_laurentaylorrr | 0:46b2c955924b | 24 | wait(0.2); |
_laurentaylorrr | 0:46b2c955924b | 25 | } |
_laurentaylorrr | 0:46b2c955924b | 26 | } |