Implement a SD card into HW6
Dependencies: SDFileSystem mbed
Fork of shomberg_hw_6 by
Diff: main.cpp
- Revision:
- 4:098e3d869055
- Parent:
- 3:56972a65cd0a
- Child:
- 5:dbd163551a58
--- a/main.cpp Thu Oct 04 13:17:04 2018 +0000 +++ b/main.cpp Mon Oct 08 20:39:35 2018 +0000 @@ -1,13 +1,15 @@ /** - MBED Analug Output Triangle Wave + MBED Analug Output Triangle Wave and PWM Wave main.cpp Purpose: Output a triangle waveform + Output a PWM Signal of same frequency + Adjust LED1 brightness with PWM Signal Adjust frequency using variable resistor Adjust amplitude using switch @author Russell Shomberg - @version 1.0 2018-09-25 + @version 1.0 2018-10-04 Issues: Frequency and amplitude only change at the start of the waveform by design @@ -25,32 +27,40 @@ // OUTPUTS Serial pc(USBTX, USBRX); // for debugging AnalogOut Aout(p18); // leave open lead on p18 for signal output +PwmOut myled(LED1); +PwmOut mypwm(p21); // VARIABLES float period; // range between ~0 and 1 (seconds) -float amplitude; // switch between 1 and -.5 +float pwmfreq; // switch between 1 and -.5 float i; // index int main() { + while(1) { - // Check settings at start of loop which are changed with - if (switchPosition==1) {amplitude = 1;} - else {amplitude = 0.5;} - period = Ain; + if (switchPosition==1) {pwmfreq = 1*period;} + else {pwmfreq = .5*period;} // Debugging code - //printf("Amplitude = %1.2f Volts\n\r", amplitude * 3.3f); - //printf("Period = %1.2f seconds\n\r", period); + //printf("PWM Frequency = %1.2f Hz\n\r", pwmfreq); + //printf("Analog Period = %1.2f seconds\n\r", period); + + //mypwm.period(period); + //mypwm = pwmfreq; for (i=0;i<1;i=i+.001){ - Aout = i*amplitude; + myled = 1-i; + mypwm = 1-i; + Aout = i; wait(0.001*period); } for (i=1;i>0;i=i-.001){ - Aout = i*amplitude; + Aout = i; + myled = 1-i; + mypwm = 1-i; wait(0.001*period); } }