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