This program is for Cansat made with BreadBoard which have pressure sensor LPS331. This program is based on http://mbed.org/users/nyamfg/code/LPS331_HelloWorld/
main.cpp
- Committer:
- ohtsuka
- Date:
- 2014-06-18
- Revision:
- 3:cb51cc4a041d
- Parent:
- 2:70ce034cfcfc
- Child:
- 4:4c01d79dd741
File content as of revision 3:cb51cc4a041d:
#include "mbed.h" #include "LPS331_I2C.h" Serial pc(USBTX, USBRX); LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); DigitalIn JP(p6); DigitalOut myled1(LED1); LocalFileSystem local("local"); Timer t; int main() { pc.printf("LPS331 Test Program.\r\n"); if(lps331.isAvailable()) { pc.printf("LPS331 is available!\r\n"); } else { pc.printf("LPS331 is unavailable!\r\n"); } lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128); lps331.setDataRate(LPS331_I2C_DATARATE_7HZ); lps331.setActive(true); FILE *fp = fopen("/local/data.txt", "a"); fprintf(fp,"**********\r\n"); fclose(fp); t.start(); while(true) { float pres, temp; int ms; if(JP==0) { break; } FILE *fp = fopen("/local/data.txt", "a"); pres = lps331.getPressure(); temp = lps331.getTemperature(); ms = t.read_ms(); pc.printf( "%10d,%6.2f,%4.1f\r\n", ms, pres, temp); fprintf(fp, "%10d,%6.2f,%4.1f\r\n", ms, pres, temp); fclose(fp); wait(0.05); myled1 = 1; wait(0.05); myled1 = 0; } }