HW6 for OCE560

Dependencies:   mbed

Fork of shomberg_hw_5 by Russell Shomberg

main.cpp

Committer:
rshomberg
Date:
2018-09-25
Revision:
1:cbee04784c60
Parent:
0:82635173a413
Child:
2:312a0a9c4485

File content as of revision 1:cbee04784c60:

/**
    MBED Analug Output Sawtooth
    main.cpp

    Purpose:    Output a sawtooth waveform
                Adjust frequency using variable resistor
                Adjust amplitude using switch

    @author Russell Shomberg
    @version 1.0 2018-09-25
    
    Issues: NTR
            

*/

// INCLUDES
#include "mbed.h"

// INPUTS
DigitalIn switchPosition(p7);
AnalogIn Ain(p20); // wire p20 to a variable resister connected from Vref and GND

// OUTPUTS
Serial pc(USBTX, USBRX);
AnalogOut Aout(p18);

// VARIABLES
float period;
float amplitude;
float i;

int main() {
    while(1) {
        
        // Check any settings which are changed with 
        if (switchPosition==1) {amplitude = 1;}
        else {amplitude = 0.5;}
        
        period = Ain;
        
        //printf("Amplitude = %1.2f Volts\n\r", amplitude * 3.3f);
        //printf("Period = %1.2f seconds\n\r", period);
        
        for (i=0;i<1;i=i+.001){
                Aout = i*amplitude;
                wait(0.001*period);
            }
            
        for (i=1;i>0;i=i-.001){
                Aout = i*amplitude;
                wait(0.001*period);
            }
    }
}