1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); unsigned char hexData[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
void setup() { Serial.begin(9600); while (!Serial) { } mySerial.begin(9600); }
void loop() { mySerial.write(hexData, 9); delay(500);
for (int i = 0, j = 0; i < 9; i++) { if (mySerial.available() > 0) { long hi, lo, CO2; int ch = mySerial.read();
if (i == 2) { hi = ch; } if (i == 3) { lo = ch; } if (i == 8) { CO2 = hi * 256 + lo; Serial.print("CO2 concentration: "); Serial.print(CO2); Serial.println("ppm"); } } } }
|