Cornell University ECE 3140 - Lab 6
/
Lab6-FinalProject
Repository for ECE 3140 Final Project
main.cpp
- Committer:
- TSSherman98
- Date:
- 2019-05-12
- Revision:
- 96:93d556043569
- Parent:
- 95:f191a7ee705b
File content as of revision 96:93d556043569:
/* ECE 3140 - Spring 2019 Lab #6 - Final Project 04//25/2019 - 05/17/2019 Nicole Lin (nl392) & Tyler Sherman (tss86) */ #include "mbed.h" /*---------------------------------------------------------------------------- GLOBAL VARIABLES *----------------------------------------------------------------------------*/ const double pi = 3.141592653589793238462; double offset = 65535/2; double amplitude = 65535/2; //this controls VOLUME double freq = 2000.0; //frequency in Hz --> controls TONE DigitalOut led1(LED1); //Red LED AnalogOut aout(DAC0_OUT); //DAC0_OUT = Analog Out pin = J4-P11 /*---------------------------------------------------------------------------- MAIN FUNCTION - Begin Program *----------------------------------------------------------------------------*/ int main() { f = freq/1000000.0; //convert seconds-->microseconds Timer clock; //begin time clock.start(); //counts time in microseconds uint16_t sample; //voltage to be output led1 = !led1; //turn on LED to indicate operation while (1) { sample = (uint16_t)((amplitude)*sin(2.0*pi*f*clock.read_us())+offset); aout.write_u16(sample); } }