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: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
VoltAlerter.cpp
- Committer:
- Bobty
- Date:
- 2015-02-22
- Revision:
- 10:72eb217def1f
File content as of revision 10:72eb217def1f:
// Detect stat of Volt-Alerter
// Device produces a square wave when voltage detected
// Cycle time of square wave around 100ms
// Rob Dobson, 2015
#include "VoltAlerter.h"
VoltAlerter::VoltAlerter(PinName pinName) :
_inPin(pinName, PullUp)
{
_curPinState = 0;
_consecutiveLows = 0;
}
void VoltAlerter::Service()
{
// Check pin
if (!_inPin)
{
_curPinState = 1;
_consecutiveLows = 0;
return;
}
// Only set state low if we get X consecutive lows
_consecutiveLows++;
if (_consecutiveLows >= CONSECUTIVE_LOWS_REQD_FOR_LOW)
{
_curPinState = 0;
// The following is just to ensure the int doesn't overflow
_consecutiveLows = CONSECUTIVE_LOWS_REQD_FOR_LOW;
}
}