Robert Banu / Mbed 2 deprecated Project

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
BRD
Date:
Fri Sep 20 07:46:16 2019 +0000
Commit message:
First;

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	Fri Sep 20 07:46:16 2019 +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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 20 07:46:16 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/d1b4690b3f8b
\ No newline at end of file