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.
Diff: main.cpp
- Revision:
- 0:14d1482ba244
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Nov 02 06:16:16 2021 +0000
@@ -0,0 +1,35 @@
+#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);
+ }
+}
\ No newline at end of file