-
Notifications
You must be signed in to change notification settings - Fork 0
getAlarm()
Arnd edited this page Aug 28, 2017
·
2 revisions
This will return which alarms have been raised. There are 4 possible return values:
Value | Meaning |
---|---|
0 | No alarms have been raised |
1 | Low temperature alarm raised |
2 | High temperature alarm raised |
3 | Both low and high temperature alarms raised |
The alarm condition remains set until it no longer applies.
DS1631_Class DS1631; // Create an instance of the DS1631
...
void setup() {
Serial.begin(SERIAL_SPEED);
while (!DS1631.begin()) { // Initialize I2C communications
Serial.println("Unable to find DS1631. Checking again in 3 seconds.");
delay(3000);
} // of loop until device is located
Serial.print("Detected ");
Serial.print(DS1631.thermometers);
Serial.println(" DS1631 devices.");
...
for (uint8_t i=0;i<DS1631.thermometers;i++) {
DS1631.setAlarmTemperature(i,0,DS1631.readTemp(i)-32); // low alarm to ambient minus 2°C
DS1631.setAlarmTemperature(i,0,DS1631.readTemp(i)+32); // high alarm to ambient plus 2°C
} // of for-next each thermometer loop
} // of setup
...
void loop() {
for (uint8_t i=0;i<DS1631.thermometers;i++) {
uint8_t alarmCode = DS1631.getAlarm(i);
if (alarmCode) {
Serial.print("F("Alarm for thermometer ");
Serial.print(i);
Serial.print(F(" "));
if (alarmCode&1) Serial.print(F("(low)"));
if (alarmCode&2) Serial.print(F("(high)"));
Serial.print(F(" raised."));
Serial.println();
} // of if-then an alarm has been raised
} // of for-next each thermometer loop
} // of main program