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.
Revision 0:d5bbef547b76, committed 2019-11-14
- Comitter:
- malyuskin
- Date:
- Thu Nov 14 22:01:13 2019 +0000
- Commit message:
- LED lamp with full control - interrupt-based switch, Analog In and PWM out
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 14 22:01:13 2019 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+InterruptIn button(A2);
+AnalogIn analog_value(A0);
+PwmOut ledpwm(A6);
+
+
+volatile bool state = 0; //initially lamp is OFF state is 0
+
+void flip() {
+ state = !state; }
+
+int main() {
+ button.rise(&flip); // attach the address of the flip function to the rising edge
+
+float meas_r; // measured analog voltage on pin A0
+
+
+ while(1) { // wait around, interrupts will interrupt this!
+
+ if (state==1){ //lamp is ON
+ //... we can control brightness here using AnalogIn
+
+ ledpwm.period_ms(10); // PWM period is 10ms
+
+ meas_r = analog_value.read();
+
+ if (meas_r<0.1) {ledpwm.write(0.1);} // this is done to have led ON even when
+ // voltage on analogIn A2 is 0
+ else ledpwm.write(meas_r);
+
+ }
+
+ else {
+ //lamp is OFF
+ //... set PWM to 0
+
+ ledpwm.period_ms(10); // PWM period is 10ms
+ ledpwm.write(0.0);
+
+ }
+ wait(0.2); }
+}
+
+
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Nov 14 22:01:13 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file