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:e8cb21f0ea92
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 11 14:21:37 2021 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+
+AnalogIn analog_value(A0);
+
+DigitalOut led(D12);
+
+void blink(float delay);
+
+int main()
+{
+ float meas_r;
+ float meas_v;
+ float delay = 1.0;
+ float delay1 = 0.4;
+
+ printf("\nAnalogIn example\n");
+
+ while(1) {
+
+ meas_r = analog_value.read(); // Read the analog input value
+ //(value from 0.0 to 1.0 = full ADC conversion range)
+
+ meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
+
+ // Display values
+ printf("measure = %f = %.0f mV\n", meas_r, meas_v);
+ printf("\n");
+
+ // LED is ON is the value is below 1V
+ if (meas_v < 1000) {
+
+ blink(delay);
+
+ }
+ else {
+
+ blink(delay1);
+ }
+
+ wait(0.2); // 0.2 second
+ }
+}
+
+void blink(float delay) {
+ led.write(1);
+ wait (delay);
+ led.write(0);
+ wait (delay);
+ }
\ No newline at end of file