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.
Dependencies: mbed
main.cpp@5:6ad8bceabbfe, 2019-08-09 (annotated)
- Committer:
- christodoulos
- Date:
- Fri Aug 09 09:40:43 2019 +0000
- Revision:
- 5:6ad8bceabbfe
- Parent:
- 3:3d51f8870e91
For Amphenol CO2
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| christodoulos | 0:d034cdad5b6d | 1 | #include "mbed.h" |
| christodoulos | 5:6ad8bceabbfe | 2 | |
| christodoulos | 5:6ad8bceabbfe | 3 | I2C i2c(A4,A5); |
| christodoulos | 5:6ad8bceabbfe | 4 | int readDelay=0.5; |
| christodoulos | 5:6ad8bceabbfe | 5 | int measureDelay=10; |
| christodoulos | 5:6ad8bceabbfe | 6 | const int ADDR_8bit = 0x15; |
| christodoulos | 5:6ad8bceabbfe | 7 | const int ADDR_6700 = 0x15 << 1; |
| christodoulos | 0:d034cdad5b6d | 8 | |
| christodoulos | 5:6ad8bceabbfe | 9 | int getCO2PPM() { |
| christodoulos | 5:6ad8bceabbfe | 10 | char data[5]; |
| christodoulos | 5:6ad8bceabbfe | 11 | char measure[5]={0x04,0x13,0x8B,0x00,0x01}; |
| christodoulos | 5:6ad8bceabbfe | 12 | i2c.start(); |
| christodoulos | 5:6ad8bceabbfe | 13 | i2c.write(ADDR_6700,measure,5); |
| christodoulos | 5:6ad8bceabbfe | 14 | i2c.stop(); |
| christodoulos | 5:6ad8bceabbfe | 15 | wait(readDelay); |
| christodoulos | 5:6ad8bceabbfe | 16 | |
| christodoulos | 5:6ad8bceabbfe | 17 | i2c.read(ADDR_6700,data,4); |
| christodoulos | 5:6ad8bceabbfe | 18 | |
| christodoulos | 5:6ad8bceabbfe | 19 | return ((data[2]&0x3F)<<8)|data[3]; |
| christodoulos | 0:d034cdad5b6d | 20 | |
| christodoulos | 5:6ad8bceabbfe | 21 | } |
| mehrnaz | 2:ef98576cd67b | 22 | int main() |
| christodoulos | 0:d034cdad5b6d | 23 | { |
| mehrnaz | 3:3d51f8870e91 | 24 | |
| christodoulos | 5:6ad8bceabbfe | 25 | while(1){ |
| christodoulos | 5:6ad8bceabbfe | 26 | int co2PPM=getCO2PPM()*100; |
| christodoulos | 5:6ad8bceabbfe | 27 | float co2percentage=(float)co2PPM/10000; |
| christodoulos | 5:6ad8bceabbfe | 28 | printf("%f\n", co2percentage); |
| christodoulos | 5:6ad8bceabbfe | 29 | } |
| mehrnaz | 3:3d51f8870e91 | 30 | |
| christodoulos | 5:6ad8bceabbfe | 31 | |
| mehrnaz | 2:ef98576cd67b | 32 | } |