Cecilia Schneider / Mbed 2 deprecated schneider_hw_4

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ccschneider
Date:
Thu Oct 18 13:52:25 2018 +0000
Commit message:
PWM;

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
diff -r 000000000000 -r efa0dd52a0d8 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 18 13:52:25 2018 +0000
@@ -0,0 +1,34 @@
+// Cecilia Schneider, OCE 360, September 9,2018
+// HW #4, PWM Output
+#include "mbed.h"
+AnalogOut Aout(p18); //oscilliscope on pin 18
+AnalogIn Ain(p20); //potentiometer on pin 20
+DigitalIn Sin(p7); //switch on pin 7 
+PwmOut PWM1(p21);
+PwmOut led(LED1);
+float ADCin;
+float Switchin;
+float i;
+float j;
+
+int main() {
+    while(1) {
+        ADCin = Ain; //
+        if (Sin == 1) { 
+            Switchin = 1; //when the switch is on, the amplitude will be 1
+        }
+        else if (Sin == 0) {
+            Switchin = 0.5; //when the switch is off, the amplitude will be 0.5
+        }
+            for (i=0;i<Switchin;i=i+0.001) {
+                Aout=i;
+                PWM1=i;
+                wait(0.001*ADCin); //allows user to control frequency with potentiometer 
+            }
+            for (j=Switchin;j>0;j=j-0.001) {
+                Aout=j;
+                PWM1=j;
+                wait(0.001*ADCin);
+            }
+    }
+}
diff -r 000000000000 -r efa0dd52a0d8 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 18 13:52:25 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file