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.
Diff: main.cpp
- Revision:
- 2:e0c00fd3c351
- Parent:
- 1:632bf9a889cc
--- a/main.cpp Wed Jan 08 05:59:40 2020 +0000
+++ b/main.cpp Thu Jan 23 08:04:00 2020 +0000
@@ -4,52 +4,99 @@
#define SENSORNUM 2
DigitalOut led(LED1);
-Serial pc(USBTX,USBRX,115200);
+Serial pc(USBTX,USBRX,921600);
//cap1
DigitalOut cap1Out(A1);
InterruptIn cap1Check(A0);
InterruptIn cap1Get(A2);
-Timer t;
+//割り込み処理(参考:https://os.mbed.com/users/okini3939/notebook/ticker_jp/)
+Ticker sig;
+
+Timer t1;
+Timer t2;
Timer constantTimer;//マイコン起動時間計測用タイマー
-uint32_t data[SENSORNUM]={0};
+uint32_t data[SENSORNUM]= {0};
uint32_t constantTime=0;
-void checkOut()
+bool outPutState=false;
+
+void check1Out()
{
- t.start();
+ t1.start();
}
-void get()
+uint32_t loop=0;
+uint32_t ave=0;
+uint32_t aveCount=0;
+uint32_t sum=0;
+
+void get1()
{
- t.stop();
+ t1.stop();
cap1Out=0;
- data[0]=t.read_us();
+ data[0]=t1.read_us();
+
+ if((data[0]<75)&&(data[0]>25)){
+ //pc.printf("c\t");
+ sum=sum+data[0];
+ aveCount++;
+ }
+
+ if(((loop%10)==0)&&(aveCount!=0)) {
+ ave=sum/aveCount;
+ for(uint8_t i=0;i<2;i++){
+ for(uint8_t i=0; i<1; i++) {
+ if(ave>=100) {
+ } else if(ave>=10) {
+ pc.printf("0");
+ } else {
+ pc.printf("00");
+ }
+ pc.printf("%u",ave);
+ //pc.printf("\t%d\t%d",sum,aveCount);
+ pc.printf("\r\n");
+ }
+ }
+ aveCount=0;
+ sum=0;
+ }else {
+ }
+ t1.reset();
+ loop++;
+}
+
+void outSig()
+{
+ //ID表示
+ cap1Out=outPutState;
+ outPutState=!outPutState;
constantTime=constantTimer.read_us();
- t.reset();
+}
+
+void timeRset()
+{
+ pc.getc();
+ constantTimer.stop();
+ constantTimer.reset();
+ constantTimer.start();
}
int main()
{
pc.printf("Hello!\r\n");
+ pc.attach(timeRset, Serial::RxIrq);
- cap1Check.rise(&checkOut);
- cap1Get.rise(&get);
-
+ cap1Check.rise(&check1Out);
+ cap1Get.rise(&get1);
constantTimer.start();
+
+ sig.attach_us(&outSig,500);
+
+ led=1;
while(1) {
- cap1Out=1;
-
- //ID表示
- pc.printf("%x,",ID);
- pc.printf("%u,",constantTime);
- for(uint8_t i=0;i<SENSORNUM;i++){
- pc.printf("%u,",data[i]);
- }
- pc.printf("\r\n");
- wait_us(data[0]*2);
}
}