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
- Committer:
- cspista
- Date:
- 2021-11-02
- Revision:
- 0:14d1482ba244
File content as of revision 0:14d1482ba244:
#include "mbed.h"
AnalogIn cds(A0); // Analog input at PA0
DigitalOut led(D10); // Led contolled by D10
uint32_t measLight(int nmeas)
{
uint32_t sum0, sum1, diff;
led = 0;
sum0 = 0;
for (int i = 0; i < nmeas; i++) {
sum0 += cds.read_u16();
}
led = 1;
sum1 = 0;
for (int i = 0; i < nmeas; i++) {
sum1 += cds.read_u16();
}
if (sum0 > sum1) {
diff= 0;
} else {
diff = (sum1 - sum0) / nmeas;
}
printf("L1: %5d L0: %5d Diff: %5d\r\n",sum1/nmeas, sum0/nmeas, diff);
return diff;
}
int main()
{
printf("\r\n Lab03_light_sensor - with averaging\r\n");
while(1) {
measLight(1000);
wait(2);
}
}