Repository for ECE 3140 Final Project

Revision:
95:f191a7ee705b
Parent:
88:bea4f2daa48c
Child:
96:93d556043569
--- a/main.cpp	Thu Apr 11 15:00:04 2019 +0100
+++ b/main.cpp	Sun May 12 03:35:54 2019 +0000
@@ -1,32 +1,37 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2018 ARM Limited
- * SPDX-License-Identifier: Apache-2.0
- */
-
+/* 
+    ECE 3140 - Spring 2019
+    Lab #6 - Final Project
+    04//25/2019 - 05/17/2019
+    Nicole Lin (nl392) & Tyler Sherman (tss86)
+*/
 #include "mbed.h"
-#include "stats_report.h"
-
-DigitalOut led1(LED1);
 
-#define SLEEP_TIME                  500 // (msec)
-#define PRINT_AFTER_N_LOOPS         20
+/*----------------------------------------------------------------------------
+                            GLOBAL VARIABLES
+ *----------------------------------------------------------------------------*/
+const double pi = 3.141592653589793238462;
+const double amplitude = 0.5f;
+const double offset = 65535/2;
+double offset = 65535/2;
+double amplitude = 65535/2;     //this controls VOLUME
+double freq = 2000.0;           //frequency in Hz --> controls TONE
 
-// main() runs in its own thread in the OS
+DigitalOut led1(LED1);          //Red LED
+AnalogOut aout(DAC0_OUT);       //DAC0_OUT = Analog Out pin = J4-P11
+
+/*----------------------------------------------------------------------------
+                        MAIN FUNCTION - Begin Program
+ *----------------------------------------------------------------------------*/
 int main()
 {
-    SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
-
-    int count = 0;
-    while (true) {
-        // Blink LED and wait 0.5 seconds
-        led1 = !led1;
-        wait_ms(SLEEP_TIME);
-
-        if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
-            // Following the main thread wait, report on the current system status
-            sys_state.report_state();
-            count = 0;
-        }
-        ++count;
+    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);
     }
 }