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
- Committer:
- rary
- Date:
- 2020-07-03
- Revision:
- 0:637769b3a60b
- Child:
- 1:17efbc35c3ba
File content as of revision 0:637769b3a60b:
#include "mbed.h"
#include "EEPROM.h"
#include "LPS33HW.h"
Timer t; //時間計測
Serial pc(USBTX, USBRX);
LPS33HW lps(p9, p10);
EEPROM e2prom(p9, p10);
#define ADDR 0xA0 //コントロールアドレス?
int pointerAddress = 0;
//main
int main()
{
int Len, n;
int h = 30;
char k[h];
char data_read[1];
//pc.baud(460800); //ボーレート変更
//readEEPROM(ADDR, pointerAddress, data_read, h);
//pc.printf("Previous data stored:%s\r\n", data_read);
t.start(); //timer Start
for(n = 0; n < 100; n++) {
lps.start(1); //気圧センサスタート
double P = lps.data_read(); //気圧データ取得
double T = t.read(); //時刻データ取得
sprintf(k, "%.3f, %.3f\r\n", T, P); //floatからchar*へ変換
Len = strlen(k) + 1; //kの文字列の長さを取得
char s[Len]; //データ格納配列
for(int i = 0; i < Len; i++) { //EEPROM書込み用配列へ格納
s[i] = k[i];
}
// write tha data
e2prom.write(ADDR, pointerAddress, s, Len);
pc.printf("%d, %d, Data written: %s\r\n", n, Len, s);
pointerAddress = pointerAddress + Len; //アドレスずらし
memset(s, '\0' , Len ); //初期化
wait(0.2);
}
//read the data
pointerAddress = 0;
pc.printf("Data read\r\n");
for(n = 0; n < 3000; n++) {
e2prom.read(ADDR, pointerAddress, data_read, 1);
pc.printf("%s", data_read);
pointerAddress = pointerAddress + 1;
memset(data_read, '\0' , 1 ); //初期化
}
pc.printf("Finish");
}