Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include <math.h> 00003 #include <stdlib.h> 00004 #include <stdio.h> 00005 00006 PwmOut pwmA(PB_3); //D3 00007 PwmOut pwmB(PB_4); //D5 00008 00009 00010 int main() { 00011 00012 char str[50]; 00013 00014 while(1) 00015 { 00016 printf("Enter a Voltage (-3.3 to 3.3 V) : \n"); 00017 gets(str); //get string from terminal 00018 00019 float voltage = atof(str); //convert str to float 00020 00021 printf("You entered: %s\n Output Voltage = %f \n", str, voltage); 00022 00023 if (voltage > 0.0){ 00024 pwmB.write(0); 00025 float duty = voltage/3.3; 00026 printf("Duty Cycle: %f \n", duty); 00027 pwmA.period(0.0001); 00028 pwmA.write(duty); 00029 } 00030 else if (voltage < 0.0){ 00031 pwmA.write(0); 00032 float duty = -(voltage)/3.3; 00033 printf("Duty Cycle: %f \n", duty); 00034 pwmB.period(0.0001); 00035 pwmB.write(duty); 00036 } 00037 else if (voltage == 0.0){ 00038 pwmA.write(0); 00039 pwmB.write(0); 00040 pwmA.period(0.0001); 00041 pwmB.period(0.0001); 00042 float duty = 0; 00043 printf("Duty Cycle: %f \n", duty); 00044 } 00045 else if (voltage > 3.3 | voltage < -3.3){ 00046 printf("Invalid Voltage input \n"); 00047 } 00048 } 00049 }
Generated on Sun Jul 17 2022 10:33:34 by
1.7.2