A collection of examples organized from basics to advanced.
Dependencies: mbed SDFileSystem
Mbed online compiler has no facility to easily manage a lot of programs or organized them in to related folders. This makes creating an examples and sample pack difficult.
This repository contains a single main.cpp file (which does very little), and a BuildOptions.h file. Simply uncomment the example you would like to compile from the build options. Each example is wrapped in a compiler directive.
If the directive does not include a description comment, it likely does not exist yet. If you would like to contribute to the Examples project, please contact me or fork and issue a pull request.
Diff: 01_Basics/Analog_In.cpp
- Revision:
- 0:b471f7764d46
diff -r 000000000000 -r b471f7764d46 01_Basics/Analog_In.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/01_Basics/Analog_In.cpp Thu Jul 04 11:04:42 2019 +0000 @@ -0,0 +1,35 @@ + +#ifdef COMPILE_Analog_In + +AnalogIn analog_value(A0); + +DigitalOut led(LED1); + +int main() +{ + float meas_r; + float meas_v; + + 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); + + // LED is ON is the value is below 1V + if (meas_v < 1000) { + led = 1; // LED ON + } else { + led = 0; // LED OFF + } + + wait(1.0); // 1 second + } +} + + +#endif \ No newline at end of file