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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:fca53941e5d5
- Child:
- 1:fd5f5be335b7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Sep 18 07:52:50 2018 +0000
@@ -0,0 +1,36 @@
+// For this example, you need the BioRobotics shield.
+// Connect POT2 (frequency)to A0
+// Connect POT1 (pwm) to A1
+#include "mbed.h"
+#include <math.h>
+
+DigitalOut gpo(D0);
+DigitalOut led(LED_RED);
+AnalogIn freq(A0);
+AnalogIn pwm(A1);
+Ticker ReadPotmetersTicker;
+volatile double frequency_Hz=1;
+volatile double pwm_pct = 50;
+volatile int on_time_us; // The time the LED should be on, in microseconds
+volatile int off_time_us;
+
+void ReadPotmeterValues(void)
+{
+ frequency_Hz = 1 + pow((double)freq.read(),4) * 50; // Frequency ranges from 1 to 50 Hz
+ pwm_pct = pwm.read() * 100;
+ on_time_us = (int) ((pwm_pct/100.0) * (1.0/frequency_Hz) * 1.0e6);
+ off_time_us = (int) (( (100.0-pwm_pct)/100.0) * (1.0/frequency_Hz) * 1.0e6);
+}
+
+int main()
+{
+ ReadPotmetersTicker.attach(ReadPotmeterValues, 0.1);
+
+ while (true)
+ {
+ led = 0; // Turn led on
+ wait_us(on_time_us);
+ led = 1; // Turn led on
+ wait_us(off_time_us);
+ }
+}
\ No newline at end of file