Charles Tritt / Mbed 2 deprecated PWM_Driver_Serial

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Tue May 12 18:37:22 2020 +0000
Parent:
3:f879eeeb5e8d
Commit message:
Analog input to PWM output with serial stream output to PC.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f879eeeb5e8d -r ab1ec7031081 main.cpp
--- a/main.cpp	Sat Feb 08 18:39:55 2020 +0000
+++ b/main.cpp	Tue May 12 18:37:22 2020 +0000
@@ -1,40 +1,33 @@
 /*
-    Project: potSerial
+    Project: PWM_Driver_Serial
     File: main.cpp
     
-    Reads from analog input, streams ASCII text to std serial using printf and
-    lights onboard LED. Also demonstrates use of floating point literal suffix
-    to eliminate warning and int constants for HIGH and LOW.
+    Reads from analog input, sends to PWM, streams ASCII text to std serial 
+    using printf. Use to test higher voltage and current transistor driver 
+    circuits.
     
     Written by: Dr. C. S. Tritt
-    Created: 2/8/20 (v. 1.0)
+    Created: 5/12/20 (v. 1.0)
     
 */
 #include "mbed.h"
 
-const int HIGH = 1; // Optional, but makes code more readable.
-const int LOW = 0; // Optional, but makes code more readable.
-const float WAIT = 0.25f; // Wait time between samples (s).
-const float LIGHT = 0.5f; // Analog value (0 to 1 scale) to light LED.
+const float WAIT = 0.5f; // Wait time between samples (s).
  
-AnalogIn analog_value(A0);
+AnalogIn myAIn(A0); // Analog input, connect to pot V divider.
+PwmOut myPWM(D10); // PWM output, Bargraph bit 1, connect to driver.
  
 DigitalOut led(LED1);
 
 int main() {
     float value; // Value to be read and sent to serial port.
     
-    printf("\nAnalog to serial example.\n");
+    printf("\nAnalog to serial & PWM example.\n");
     
     while(true) {
-        value = analog_value.read(); // Read the analog input value (0 to 1)
+        value = myAIn.read(); // Read the analog input value (0 to 1)
+        myPWM.write(value); // Write value read to PWM pin.
         printf("%f\n", value); // Send value as text via serial port.
-        if (value > LIGHT) { // Activate built-in LED based on LIGHT value.
-          led.write(HIGH);
-        }
-        else {
-          led.write(LOW);
-        }
         wait(WAIT); // Wait WAIT seconds.
     }
 }
\ No newline at end of file