ELCT 302 / Mbed 2 deprecated drivelab3

Dependencies:   mbed

Revision:
1:128dc77d025a
Parent:
0:bd04e6ac5a2c
Child:
2:01372422b0c7
diff -r bd04e6ac5a2c -r 128dc77d025a main.cpp
--- a/main.cpp	Mon Feb 01 16:01:48 2021 +0000
+++ b/main.cpp	Mon Feb 01 16:23:33 2021 +0000
@@ -7,16 +7,14 @@
 AnalogIn input(PTB0);
 PwmOut output(PTE21);
 Ticker updater;
- 
-const double fullSpeed = .9; // duty cycle for full speed
-const double slowSpeed = .4; // duty cycle for slow speed
-float v = 0;
-float d = fullSpeed;
+
+float v = 0.0;
+float d = 0.0;
  
 void pwmUpdate()
 {
     v = input.read();
-    d = slowSpeed + v*(fullSpeed - slowSpeed);; // calculates duty cycle from input
+    d = v; // sets DC to voltage
     if( abs(d - output.read()) > 0.001) //only updates the duty cycle if there is a change in the duty cycle greater than 0.3%
          output.write(d);
 }
@@ -25,7 +23,7 @@
 {
     output.period(0.00005f); // 20 kHz control signal
     // attaches pwmUpdate function to the ticker with a period of 20ms
-    updater.attach(&pwmUpdate,0.02f);
+    updater.attach(&pwmUpdate,0.00005f);
     std::cout << "AnalogIn: " << v << " Duty Cycle: " << d << std::endl;
     while(1) {} // do nothing
 }
\ No newline at end of file