Cornell University ECE 3140 - Lab 6
/
Lab6-FinalProject
Repository for ECE 3140 Final Project
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 ECE 3140 - Spring 2019 00003 Lab #6 - Final Project 00004 04//25/2019 - 05/17/2019 00005 Nicole Lin (nl392) & Tyler Sherman (tss86) 00006 */ 00007 #include "mbed.h" 00008 00009 /*---------------------------------------------------------------------------- 00010 GLOBAL VARIABLES 00011 *----------------------------------------------------------------------------*/ 00012 const double pi = 3.141592653589793238462; 00013 double offset = 65535/2; 00014 double amplitude = 65535/2; //this controls VOLUME 00015 double freq = 2000.0; //frequency in Hz --> controls TONE 00016 00017 DigitalOut led1(LED1); //Red LED 00018 AnalogOut aout(DAC0_OUT); //DAC0_OUT = Analog Out pin = J4-P11 00019 00020 /*---------------------------------------------------------------------------- 00021 MAIN FUNCTION - Begin Program 00022 *----------------------------------------------------------------------------*/ 00023 int main() 00024 { 00025 f = freq/1000000.0; //convert seconds-->microseconds 00026 Timer clock; //begin time 00027 clock.start(); //counts time in microseconds 00028 uint16_t sample; //voltage to be output 00029 led1 = !led1; //turn on LED to indicate operation 00030 00031 while (1) { 00032 sample = (uint16_t)((amplitude)*sin(2.0*pi*f*clock.read_us())+offset); 00033 aout.write_u16(sample); 00034 } 00035 }
Generated on Fri Jul 15 2022 19:47:26 by 1.7.2