1st part of the exercises

Dependencies:   MODSERIAL mbed

Files at this revision

API Documentation at this revision

Comitter:
bjonkheer
Date:
Thu Sep 20 12:17:36 2018 +0000
Commit message:
werkend

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r 704340a59525 MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Thu Sep 20 12:17:36 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#da0788f0bd77
diff -r 000000000000 -r 704340a59525 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 20 12:17:36 2018 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+
+Ticker potmeterticker;
+DigitalIn button1(D2);
+DigitalIn button2(D3);
+AnalogIn potmeter(A0);
+DigitalOut led(D4);
+MODSERIAL pc(USBTX, USBRX);
+volatile float pwmvalue;
+volatile double pwm_pct;
+volatile int on_time_us; // The time the LED should be on, in microseconds
+volatile int off_time_us;
+
+
+void ReadPotmeterValues()
+{
+    int frequency_Hz = 10000; 
+    pwm_pct = potmeter.read() * 100;
+    on_time_us = (int) ((pwm_pct/100.0) * (1.0/frequency_Hz) * 1.0e7);
+    off_time_us = (int) (( (100.0-pwm_pct)/100.0) * (1.0/frequency_Hz) * 1.0e7);
+}
+
+int main()
+{
+    pc.baud(115200);
+    pc.printf("Hello World!\r\n");
+    potmeterticker.attach(ReadPotmeterValues, 0.5);
+    
+    while (true) {
+        led = 1;
+        pc.printf("%i\r\n",on_time_us);
+        wait_us(on_time_us);
+        led = 0; // Turn led off
+        wait_us(off_time_us);
+        //ReadPotmeterValues();
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 704340a59525 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 20 12:17:36 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file