Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HEPTA_CDH HEPTA_EPS HEPTA_SENSOR mbed
Revision 32:a9f3966b8759, committed 2022-09-07
- Comitter:
- csmk18112
- Date:
- Wed Sep 07 09:45:04 2022 +0000
- Parent:
- 31:c03fdf6f0138
- Commit message:
- v1
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Aug 19 04:50:42 2022 +0000
+++ b/main.cpp Wed Sep 07 09:45:04 2022 +0000
@@ -1,18 +1,73 @@
#include "mbed.h"
#include "HEPTA_EPS.h"
+#include "HEPTA_SENSOR.h"
#include "HEPTA_CDH.h"
-#include "HEPTA_SENSOR.h"
-Serial pc(USBTX,USBRX);
+HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
+
+Serial pc(USBTX, USBRX, 9600);
HEPTA_EPS eps(p16,p26);
-HEPTA_CDH cdh(p5,p6,p7,p8,"sd");
HEPTA_SENSOR sensor(p17,
p28,p27,0x19,0x69,0x13,
p13, p14,p25,p24);
-int main()
-{
- sensor.gps_setting();
- pc.printf("GPS Raw Data Mode\r\n");
- while(1) pc.putc(sensor.getc());
+AnalogIn mic(p15); //microphone input
+
+DigitalOut led1(LED1); // following leds are used to visualy show amplitude of sound
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+Timer sattime;
+
+void record(float* sampleArr) {
+ //record sound for 1 second
+ for(int i=0; i<4000; i++) {
+ sampleArr[i] = mic.read(); //put samples in array
+ wait(0.000125f); //sample rate of 8000 Hz
+ }
+}
+
+void volume(){
+ //the following lights up the onboard LEDs depending on the amplitude of sound
+ led1 = (mic > 0.5f) ? 1 : 0;
+ led2 = (mic > 0.6f) ? 1 : 0;
+ led3 = (mic > 0.7f) ? 1 : 0;
+ led4 = (mic > 0.8f) ? 1 : 0;
+}
+
+int rcmd=1;
+
+int main() {
+ float sampleArr[4000];
+ sattime.start();
+ float starttime=sattime.read();
+ pc.printf("Start time: %f\r\n",starttime);
+ pc.baud(9600);
+ while(1){
+ volume();
+ if(rcmd == 1) {
+ record(sampleArr);
+ float endtime=sattime.read();
+ pc.printf("The following data has been written:\r\n");
+ for (int j=0; j<400; j++) {
+ if (j == 0){
+ pc.printf("%f = %f\r\n",starttime,sampleArr[j]);
+ }
+ else {
+ pc.printf("%f = %f\r\n",endtime,sampleArr[j]);
+ }
+ }
+ FILE *fp = fopen("/sd/mydir/test2.txt","w");
+ if(fp == NULL) {
+ error("Could not open file for write\r\n");
+ }
+ for (int j=0; j<400; j++) {
+ fprintf(fp,"%f\r\n",sampleArr[j]);
+ }
+ fclose(fp);
+ wait(5);
+ pc.printf("Writing data complete\r\n");
+ }
+ }
}
\ No newline at end of file