Implement a SD card into HW6

Dependencies:   SDFileSystem mbed

Fork of shomberg_hw_6 by Russell Shomberg

Committer:
rshomberg
Date:
Tue Sep 25 14:59:23 2018 +0000
Revision:
1:cbee04784c60
Parent:
0:82635173a413
Child:
2:312a0a9c4485
finished assignment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rshomberg 0:82635173a413 1 /**
rshomberg 0:82635173a413 2 MBED Analug Output Sawtooth
rshomberg 0:82635173a413 3 main.cpp
rshomberg 0:82635173a413 4
rshomberg 0:82635173a413 5 Purpose: Output a sawtooth waveform
rshomberg 0:82635173a413 6 Adjust frequency using variable resistor
rshomberg 0:82635173a413 7 Adjust amplitude using switch
rshomberg 0:82635173a413 8
rshomberg 0:82635173a413 9 @author Russell Shomberg
rshomberg 0:82635173a413 10 @version 1.0 2018-09-25
rshomberg 0:82635173a413 11
rshomberg 0:82635173a413 12 Issues: NTR
rshomberg 0:82635173a413 13
rshomberg 0:82635173a413 14
rshomberg 0:82635173a413 15 */
rshomberg 0:82635173a413 16
rshomberg 0:82635173a413 17 // INCLUDES
rshomberg 0:82635173a413 18 #include "mbed.h"
rshomberg 0:82635173a413 19
rshomberg 0:82635173a413 20 // INPUTS
rshomberg 0:82635173a413 21 DigitalIn switchPosition(p7);
rshomberg 0:82635173a413 22 AnalogIn Ain(p20); // wire p20 to a variable resister connected from Vref and GND
rshomberg 0:82635173a413 23
rshomberg 0:82635173a413 24 // OUTPUTS
rshomberg 0:82635173a413 25 Serial pc(USBTX, USBRX);
rshomberg 0:82635173a413 26 AnalogOut Aout(p18);
rshomberg 0:82635173a413 27
rshomberg 0:82635173a413 28 // VARIABLES
rshomberg 1:cbee04784c60 29 float period;
rshomberg 1:cbee04784c60 30 float amplitude;
rshomberg 0:82635173a413 31 float i;
rshomberg 0:82635173a413 32
rshomberg 0:82635173a413 33 int main() {
rshomberg 0:82635173a413 34 while(1) {
rshomberg 1:cbee04784c60 35
rshomberg 1:cbee04784c60 36 // Check any settings which are changed with
rshomberg 1:cbee04784c60 37 if (switchPosition==1) {amplitude = 1;}
rshomberg 1:cbee04784c60 38 else {amplitude = 0.5;}
rshomberg 1:cbee04784c60 39
rshomberg 1:cbee04784c60 40 period = Ain;
rshomberg 1:cbee04784c60 41
rshomberg 1:cbee04784c60 42 //printf("Amplitude = %1.2f Volts\n\r", amplitude * 3.3f);
rshomberg 1:cbee04784c60 43 //printf("Period = %1.2f seconds\n\r", period);
rshomberg 1:cbee04784c60 44
rshomberg 1:cbee04784c60 45 for (i=0;i<1;i=i+.001){
rshomberg 1:cbee04784c60 46 Aout = i*amplitude;
rshomberg 1:cbee04784c60 47 wait(0.001*period);
rshomberg 0:82635173a413 48 }
rshomberg 1:cbee04784c60 49
rshomberg 1:cbee04784c60 50 for (i=1;i>0;i=i-.001){
rshomberg 1:cbee04784c60 51 Aout = i*amplitude;
rshomberg 1:cbee04784c60 52 wait(0.001*period);
rshomberg 0:82635173a413 53 }
rshomberg 0:82635173a413 54 }
rshomberg 0:82635173a413 55 }