mySerial.begin(9600); // Start serial communications with sensor
mySerial.println("M 6"); // send Mode for Z and z outputs
mySerial.println("K 1"); // set streaming mode
}
void loop(void) {
if (sleep_count % sleep_total == 0) {
// CODE TO BE EXECUTED PERIODICALLY
Serial.println("wake!");
ISR(WDT_vect)
{
sleep_count ++; // keep track of how many sleep cycles
}
void deviceINIT(){
// SD module init
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
//RTC init
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
O2_value();
}
void StartTimeCorrect(){
DateTime now = rtc.now();
int c_time = (60-now.minute())%15;
complement_delay(c_time);
Serial.println("end wait");
delay(100);
}
void delay1min(){
delay(30000);
delay(30000);
}
void complement_delay(int c){
for (int i=0;i<c;i++){
delay1min();
}
}
int fill_buffer(void){
// Fill buffer with sensor ascii data
ind = 0;
while(buffer[ind-1] != 0x0A){ // Read sensor and fill buffer up to 0XA = CR
if(mySerial.available()){
buffer[ind] = mySerial.read();
ind++;
}
}
// buffer() now filled with sensor ascii data
// ind contains the number of characters loaded into buffer up to 0xA = CR
ind = ind -2; // decrement buffer to exactly match last numerical character
}
String format_output(){ // read buffer, extract 6 ASCII chars, convert to PPM and print
int co2 =0;
int index=8; double multiplier = 10;
co2 = buffer[15-index]-0x30;
co2 = co2+((buffer[14-index]-0x30)*10);
co2 +=(buffer[13-index]-0x30)*100;
co2 +=(buffer[12-index]-0x30)*1000;
co2 +=(buffer[11-index]-0x30)*10000;