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@0:637769b3a60b, 2020-07-03 (annotated)
- Committer:
- rary
- Date:
- Fri Jul 03 02:51:53 2020 +0000
- Revision:
- 0:637769b3a60b
- Child:
- 1:17efbc35c3ba
To produce library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rary | 0:637769b3a60b | 1 | #include "mbed.h" |
| rary | 0:637769b3a60b | 2 | #include "EEPROM.h" |
| rary | 0:637769b3a60b | 3 | #include "LPS33HW.h" |
| rary | 0:637769b3a60b | 4 | |
| rary | 0:637769b3a60b | 5 | Timer t; //時間計測 |
| rary | 0:637769b3a60b | 6 | Serial pc(USBTX, USBRX); |
| rary | 0:637769b3a60b | 7 | LPS33HW lps(p9, p10); |
| rary | 0:637769b3a60b | 8 | EEPROM e2prom(p9, p10); |
| rary | 0:637769b3a60b | 9 | |
| rary | 0:637769b3a60b | 10 | |
| rary | 0:637769b3a60b | 11 | #define ADDR 0xA0 //コントロールアドレス? |
| rary | 0:637769b3a60b | 12 | |
| rary | 0:637769b3a60b | 13 | int pointerAddress = 0; |
| rary | 0:637769b3a60b | 14 | |
| rary | 0:637769b3a60b | 15 | //main |
| rary | 0:637769b3a60b | 16 | int main() |
| rary | 0:637769b3a60b | 17 | { |
| rary | 0:637769b3a60b | 18 | int Len, n; |
| rary | 0:637769b3a60b | 19 | int h = 30; |
| rary | 0:637769b3a60b | 20 | char k[h]; |
| rary | 0:637769b3a60b | 21 | char data_read[1]; |
| rary | 0:637769b3a60b | 22 | //pc.baud(460800); //ボーレート変更 |
| rary | 0:637769b3a60b | 23 | |
| rary | 0:637769b3a60b | 24 | //readEEPROM(ADDR, pointerAddress, data_read, h); |
| rary | 0:637769b3a60b | 25 | //pc.printf("Previous data stored:%s\r\n", data_read); |
| rary | 0:637769b3a60b | 26 | |
| rary | 0:637769b3a60b | 27 | t.start(); //timer Start |
| rary | 0:637769b3a60b | 28 | |
| rary | 0:637769b3a60b | 29 | for(n = 0; n < 100; n++) { |
| rary | 0:637769b3a60b | 30 | lps.start(1); //気圧センサスタート |
| rary | 0:637769b3a60b | 31 | double P = lps.data_read(); //気圧データ取得 |
| rary | 0:637769b3a60b | 32 | double T = t.read(); //時刻データ取得 |
| rary | 0:637769b3a60b | 33 | |
| rary | 0:637769b3a60b | 34 | sprintf(k, "%.3f, %.3f\r\n", T, P); //floatからchar*へ変換 |
| rary | 0:637769b3a60b | 35 | |
| rary | 0:637769b3a60b | 36 | Len = strlen(k) + 1; //kの文字列の長さを取得 |
| rary | 0:637769b3a60b | 37 | |
| rary | 0:637769b3a60b | 38 | char s[Len]; //データ格納配列 |
| rary | 0:637769b3a60b | 39 | |
| rary | 0:637769b3a60b | 40 | for(int i = 0; i < Len; i++) { //EEPROM書込み用配列へ格納 |
| rary | 0:637769b3a60b | 41 | s[i] = k[i]; |
| rary | 0:637769b3a60b | 42 | } |
| rary | 0:637769b3a60b | 43 | |
| rary | 0:637769b3a60b | 44 | // write tha data |
| rary | 0:637769b3a60b | 45 | e2prom.write(ADDR, pointerAddress, s, Len); |
| rary | 0:637769b3a60b | 46 | pc.printf("%d, %d, Data written: %s\r\n", n, Len, s); |
| rary | 0:637769b3a60b | 47 | |
| rary | 0:637769b3a60b | 48 | pointerAddress = pointerAddress + Len; //アドレスずらし |
| rary | 0:637769b3a60b | 49 | memset(s, '\0' , Len ); //初期化 |
| rary | 0:637769b3a60b | 50 | wait(0.2); |
| rary | 0:637769b3a60b | 51 | } |
| rary | 0:637769b3a60b | 52 | |
| rary | 0:637769b3a60b | 53 | //read the data |
| rary | 0:637769b3a60b | 54 | pointerAddress = 0; |
| rary | 0:637769b3a60b | 55 | pc.printf("Data read\r\n"); |
| rary | 0:637769b3a60b | 56 | |
| rary | 0:637769b3a60b | 57 | for(n = 0; n < 3000; n++) { |
| rary | 0:637769b3a60b | 58 | e2prom.read(ADDR, pointerAddress, data_read, 1); |
| rary | 0:637769b3a60b | 59 | pc.printf("%s", data_read); |
| rary | 0:637769b3a60b | 60 | |
| rary | 0:637769b3a60b | 61 | pointerAddress = pointerAddress + 1; |
| rary | 0:637769b3a60b | 62 | memset(data_read, '\0' , 1 ); //初期化 |
| rary | 0:637769b3a60b | 63 | } |
| rary | 0:637769b3a60b | 64 | |
| rary | 0:637769b3a60b | 65 | pc.printf("Finish"); |
| rary | 0:637769b3a60b | 66 | } |