Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Treat pacs lock as a digital input (instead of analog).
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lindros committed Feb 21, 2014
1 parent 50fbc5c commit 6c3e5fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
32 changes: 12 additions & 20 deletions PACSPeripheral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ void PACSPeripheral::initialize() {
* We set them to inactive to avoid any issues if the pin
* is not actually connected to anything.
*/

int initialLevel = ((activeLevel == HIGH) ? LOW : HIGH);
currentLevel = previousLevel = initialLevel;
levelChanged = false;

switch (type) {
case DOORMONITOR:
case REX:
pinMode(pin, OUTPUT);
break;

digitalWrite(pin, initialLevel);
break;

case GREENLED:
case BEEPER:
pinMode(pin, INPUT);
break;

case LOCK:
pinMode(pin, INPUT);
pinMode(pin, INPUT);
digitalWrite(pin, initialLevel);
break;

default:
break;
}
int initialLevel = ((activeLevel == HIGH) ? LOW : HIGH);
digitalWrite(pin, initialLevel);
currentLevel = previousLevel = initialLevel;
levelChanged = false;
}

/*
Expand All @@ -78,18 +78,10 @@ void PACSPeripheral::updateLevels() {
case REX:
case GREENLED:
case BEEPER:
currentLevel = digitalRead(pin);
break;
case LOCK:
voltage = (analogRead(pin) * (VOLTAGE_INPUT / 1023.0));
if (voltage >= VOLTAGE_THRESHOLD_HIGH) {
currentLevel = HIGH;
}
else if (voltage < VOLTAGE_THRESHOLD_LOW) {
currentLevel = LOW;
}
currentLevel = digitalRead(pin);
break;

default:
break;
}
Expand Down
4 changes: 0 additions & 4 deletions PACSPeripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#include <Arduino.h>

#define VOLTAGE_INPUT 5.0f // What is the input voltage from lock. (Should be max 5V, otherwise we damage the hardware)
#define VOLTAGE_THRESHOLD_HIGH 4.5f // At what value we regard the lock as being locked/unlocked.
#define VOLTAGE_THRESHOLD_LOW 0.9f // At what value we regard the lock as being locked/unlocked.

#define PERIPHERAL_ID_MAX_LENGTH 16 // The max number of characters for the ID.

typedef enum {GREENLED, BEEPER, DOORMONITOR, REX, LOCK} PACSPeripheralType_t;
Expand Down

0 comments on commit 6c3e5fd

Please sign in to comment.