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.
main.cpp@1:632bf9a889cc, 2020-01-08 (annotated)
- Committer:
- HidetoN
- Date:
- Wed Jan 08 05:59:40 2020 +0000
- Revision:
- 1:632bf9a889cc
- Parent:
- 0:1025ad5aabba
- Child:
- 2:e0c00fd3c351
add constantTime
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| HidetoN | 0:1025ad5aabba | 1 | #include "mbed.h" |
| HidetoN | 0:1025ad5aabba | 2 | |
| HidetoN | 0:1025ad5aabba | 3 | #define ID 0x00 |
| HidetoN | 1:632bf9a889cc | 4 | #define SENSORNUM 2 |
| HidetoN | 0:1025ad5aabba | 5 | |
| HidetoN | 0:1025ad5aabba | 6 | DigitalOut led(LED1); |
| HidetoN | 0:1025ad5aabba | 7 | Serial pc(USBTX,USBRX,115200); |
| HidetoN | 0:1025ad5aabba | 8 | |
| HidetoN | 0:1025ad5aabba | 9 | //cap1 |
| HidetoN | 0:1025ad5aabba | 10 | DigitalOut cap1Out(A1); |
| HidetoN | 0:1025ad5aabba | 11 | InterruptIn cap1Check(A0); |
| HidetoN | 0:1025ad5aabba | 12 | InterruptIn cap1Get(A2); |
| HidetoN | 0:1025ad5aabba | 13 | |
| HidetoN | 0:1025ad5aabba | 14 | Timer t; |
| HidetoN | 0:1025ad5aabba | 15 | Timer constantTimer;//マイコン起動時間計測用タイマー |
| HidetoN | 1:632bf9a889cc | 16 | uint32_t data[SENSORNUM]={0}; |
| HidetoN | 1:632bf9a889cc | 17 | |
| HidetoN | 1:632bf9a889cc | 18 | uint32_t constantTime=0; |
| HidetoN | 0:1025ad5aabba | 19 | |
| HidetoN | 0:1025ad5aabba | 20 | void checkOut() |
| HidetoN | 0:1025ad5aabba | 21 | { |
| HidetoN | 0:1025ad5aabba | 22 | t.start(); |
| HidetoN | 0:1025ad5aabba | 23 | } |
| HidetoN | 0:1025ad5aabba | 24 | |
| HidetoN | 0:1025ad5aabba | 25 | void get() |
| HidetoN | 0:1025ad5aabba | 26 | { |
| HidetoN | 0:1025ad5aabba | 27 | t.stop(); |
| HidetoN | 0:1025ad5aabba | 28 | cap1Out=0; |
| HidetoN | 1:632bf9a889cc | 29 | data[0]=t.read_us(); |
| HidetoN | 1:632bf9a889cc | 30 | constantTime=constantTimer.read_us(); |
| HidetoN | 0:1025ad5aabba | 31 | t.reset(); |
| HidetoN | 0:1025ad5aabba | 32 | } |
| HidetoN | 0:1025ad5aabba | 33 | |
| HidetoN | 0:1025ad5aabba | 34 | int main() |
| HidetoN | 0:1025ad5aabba | 35 | { |
| HidetoN | 0:1025ad5aabba | 36 | |
| HidetoN | 0:1025ad5aabba | 37 | pc.printf("Hello!\r\n"); |
| HidetoN | 0:1025ad5aabba | 38 | |
| HidetoN | 0:1025ad5aabba | 39 | cap1Check.rise(&checkOut); |
| HidetoN | 0:1025ad5aabba | 40 | cap1Get.rise(&get); |
| HidetoN | 1:632bf9a889cc | 41 | |
| HidetoN | 1:632bf9a889cc | 42 | constantTimer.start(); |
| HidetoN | 0:1025ad5aabba | 43 | while(1) { |
| HidetoN | 0:1025ad5aabba | 44 | cap1Out=1; |
| HidetoN | 0:1025ad5aabba | 45 | |
| HidetoN | 0:1025ad5aabba | 46 | //ID表示 |
| HidetoN | 0:1025ad5aabba | 47 | pc.printf("%x,",ID); |
| HidetoN | 1:632bf9a889cc | 48 | pc.printf("%u,",constantTime); |
| HidetoN | 1:632bf9a889cc | 49 | for(uint8_t i=0;i<SENSORNUM;i++){ |
| HidetoN | 1:632bf9a889cc | 50 | pc.printf("%u,",data[i]); |
| HidetoN | 1:632bf9a889cc | 51 | } |
| HidetoN | 0:1025ad5aabba | 52 | pc.printf("\r\n"); |
| HidetoN | 1:632bf9a889cc | 53 | wait_us(data[0]*2); |
| HidetoN | 0:1025ad5aabba | 54 | } |
| HidetoN | 0:1025ad5aabba | 55 | } |