~
Dependencies: 4DGL-uLCD-SE SDFileSystem
Diff: main.cpp
- Revision:
- 5:151b0fa1fb44
- Parent:
- 4:f5bc5d9a790b
- Child:
- 6:708e878d4374
--- a/main.cpp Fri Sep 23 19:45:44 2016 +0000 +++ b/main.cpp Sun Sep 25 18:59:05 2016 +0000 @@ -1,7 +1,20 @@ #include "mbed.h" +// serial com, print statements sent to pc now +Serial pc(USBTX, USBRX); + +/* part 1 +AnalogOut aout(p18); +AnalogIn ain(p15); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); +*/ + +/* part 8 BusOut myleds(LED1,LED2,LED3,LED4); - + class microphone { public : @@ -25,84 +38,43 @@ } microphone mymicrophone(p16); - -int main() -{ - while(1) { -//read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display - myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0); -//Use an 8kHz audio sample rate (phone quality audio); - wait(1.0/8000.0); - } -} -/* - -AnalogOut aout(p18); -AnalogIn ain(p15); -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); +*/ int main() { - - - /* - // part 1 + /* part 1 const double pi = 3.141592653589793238462; const double amplitude = 1.0f; const double offset = 65535/2; // 0xFFFF/2 double rads = 0.0; uint16_t sample = 0; - - while(1) { - // analog out - - for (int i = 0; i < 720; i++) { - rads = (pi * i) / 180.0f; - sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); - aout.write_u16(sample); - } - - - // analog in - led1 = (ain > 0.2f) ? 1 : 0; - led2 = (ain > 0.4f) ? 1 : 0; - led3 = (ain > 0.6f) ? 1 : 0; - led4 = (ain > 0.8f) ? 1 : 0; - wait(.01); - } - - /* part 5 - // demo from https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/ - - printf("Example network-socket HTTP client\n"); + */ - // Brings up the network interface - eth.connect(); - const char *ip = eth.get_ip_address(); - const char *mac = eth.get_mac_address(); - printf("IP address is: %s\n", ip ? ip : "No IP"); - printf("MAC address is: %s\n", mac ? mac : "No MAC"); - - // Open a socket on the network interface, and create a TCP connection to mbed.org - socket.open(ð); - socket.connect("developer.mbed.org", 80); - - // Send a simple http request - char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; - int scount = socket.send(sbuffer, sizeof sbuffer); - printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); - - // Recieve a simple http response and print out the response line - char rbuffer[64]; - int rcount = socket.recv(rbuffer, sizeof rbuffer); - printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); - - // Close the socket to return its memory and bring down the network interface - socket.close(); - eth.disconnect(); - - printf("Done\n"); - */ +// while(1) { +// +// /* part 1 +// +// // analog out +// for (int i = 0; i < 720; i++) { +// rads = (pi * i) / 180.0f; +// sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); +// aout.write_u16(sample); +// } +// +// // analog in +// led1 = (ain > 0.2f) ? 1 : 0; +// led2 = (ain > 0.4f) ? 1 : 0; +// led3 = (ain > 0.6f) ? 1 : 0; +// led4 = (ain > 0.8f) ? 1 : 0; +// wait(.01); +// */ +// +// /* part 8 +// //read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display +// myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0); +// //Use an 8kHz audio sample rate (phone quality audio); +// wait(1.0/8000.0); +// */ +// } + return 0; +}