CLTP統合検証プログラム_気圧とxbeeのみで,圧電スピーカの実装が必要
Dependencies: mbed HEPTA_CDH_lite LPS25HB_I2C
Revision 3:08260b6b0828, committed 2022-08-16
- Comitter:
- wasabimal
- Date:
- Tue Aug 16 10:50:58 2022 +0000
- Parent:
- 2:bc6e512b58ac
- Commit message:
- sd
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Aug 16 10:05:12 2022 +0000 +++ b/main.cpp Tue Aug 16 10:50:58 2022 +0000 @@ -1,3 +1,10 @@ +#define mC 261.626 +#define mD 293.665 +#define mE 329.628 +#define mF 349.228 +#define mG 391.995 +#define mA 440.000 +#define mB 493.883 #include "mbed.h" #include "LPS.h" #include "HEPTA_CDH.h" @@ -6,14 +13,23 @@ Serial xbee(D1, D0); // tx, rx I2C i2c(D4,D5); LPS ps(i2c); +DigitalOut sp1(A0); HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd"); Ticker press; +Ticker sound; int i; int ct = 0; float pressure = 0; float altitude = 0; float temperature = 0; char cmd1,cmd2,cmd3; +int oto = 0; +float mm[]={mC*4,mD*4,mE*4,mF*4,mG*4,mA*4,mB*4,mC*8}; //timbre +void tick(void) +{ + sp1.write(oto); + oto=!oto; +} void pre() { xbee.printf("%.2f %.2f %.2f \r\n",pressure,altitude,temperature); } @@ -21,7 +37,6 @@ //Display from satellite to PC via xbee. pc.printf("settig start\r\n"); xbee.printf("settig start\r\n"); - //Create a file to save the data acquired from the sensor to a microSD card //Also, if there is no microSD card, this error statement will be displayed mkdir("/sd/mydir", 0777); @@ -29,25 +44,20 @@ if(fp == NULL) { error("Could not open file for write\r\n"); } - //If there is no Barometric Pressure Sensors, this error statement will appear in teraterm if (!ps.init()){//2 printf("Failed to autodetect pressure sensor!\r\n"); while (1); }//2 ps.enableDefault(); - //Display "begin" in teraterm and save it to SDcard pc.printf("begin\r\n"); xbee.printf("begin\r\n"); fprintf(fp,"begin\r\n"); for (;;) {//2 - //if (pc.readable()) xbee.putc(pc.getc()); if (xbee.readable()) {//3 pc.putc(xbee.getc()); cmd1 = xbee.getc(); - //char cmd1 = xbee.getc();//cmd共有 - //Input "m", the sensor data is displayed on the teraterm. //And the acquired data is saved to the SD card. if(cmd1 == 'm'){//4 @@ -55,12 +65,10 @@ fprintf(fp,"start\r\n"); xbee.printf("start\r\n"); t.start(); - cmd1 = '\0'; - - pc.printf("p [mbar]\ta [m]\tdeg [C]\r\n"); - xbee.printf("p [mbar]\ta [m]\tdeg [C]\r\n"); - fprintf(fp,"p [mbar]\ta [m]\tdeg [C]\r\n"); + pc.printf("p[mbar] a[m] deg[C]\r\n"); + xbee.printf("p[mbar] a[m] deg[C]\r\n"); + fprintf(fp,"p[mbar] a[m] deg[C]\r\n"); fclose(fp); press.attach(&pre, 0.1); //Save sensor acquisition data to SD card every 10 times @@ -70,25 +78,40 @@ pressure = ps.readPressureMillibars(); altitude = ps.pressureToAltitudeMeters(pressure); temperature = ps.readTemperatureC(); - fprintf(fp,"%d %.2f\t \t%.2f \t%.2f \r\n",ct,pressure,altitude,temperature); + fprintf(fp,"%d %.2f %.2f %.2f\r\n",ct,pressure,altitude,temperature); ct = ct + 1; - //if (pc.readable()) xbee.putc(pc.getc()); if (xbee.readable()){//7 pc.putc(xbee.getc()); cmd2 = xbee.getc(); - //char cmd2 = xbee.getc(); - //xbee.printf("%c\r\n",cmd); + //Input "n", The command finishes acquiring air pressure if(cmd2 == 'n'){//8 press.detach(); - pc.printf("end\r\n"); - pc.printf("time = %f",t.read()); + xbee.printf("end\r\n"); + xbee.printf("time = %f",t.read()); fprintf(fp,"time = %f",t.read()); t.stop(); fclose(fp); cmd2 = '\0'; - return 0; - }//8 - }//7 + while(1){//9 + for(i=0;i < sizeof(mm)/sizeof(mm[0]);i++) { + sound.attach(&tick,1.0/mm[i]/2.0); //If warning appear, ignore + wait(0.5f); + }//10 + sound.detach(); + i = 0; + if (xbee.readable()){//10 + pc.putc(xbee.getc()); + cmd3 = xbee.getc(); + //Input "k", The command terminates the program. + if(cmd3 == 'k'){//11 + pc.printf("end\r\n"); + sound.detach(); + //return 0; + }//11 + }//10 + }//9 + }//8 + }//7 wait_us(1); }//6 fclose(fp);