Skip to content

Commit

Permalink
Reset command, display last event on LCD.
Browse files Browse the repository at this point in the history
  • Loading branch information
teabot committed Feb 4, 2011
1 parent 1ad163a commit 524045e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -7,6 +7,7 @@ Serial control format
'X' - beam off
'L' - beam on
'S' - poll for status
'R' - reset counter

Status response - sent on event or on poll:

Expand Down
37 changes: 27 additions & 10 deletions spacensus.pde
Expand Up @@ -63,6 +63,7 @@ void setup()
pinMode(BEAM_IN, INPUT);
pinMode(BEAM_OUT, INPUT);

lcd.begin(16, 2);
lcd.print("spacensus v0.1");
}

Expand Down Expand Up @@ -126,7 +127,6 @@ void handleBeamBreak(int interrupt, int gotoState, int waitingForState, int incr
updateSerial = true;
}
state = DELAY;

}
}

Expand All @@ -146,8 +146,8 @@ void checkBeamsForObstructions() {
if (!beamInhibited) {
beamInDurationMs = calculateBeamBreakInterval(BEAM_IN, beamInDurationMs);
beamOutDurationMs = calculateBeamBreakInterval(BEAM_OUT, beamOutDurationMs);

if (!beamInDurationMs >= OBSTRUCTION_INTERVAL_MS || beamOutDurationMs >= OBSTRUCTION_INTERVAL_MS) {
if (beamInDurationMs >= OBSTRUCTION_INTERVAL_MS || beamOutDurationMs >= OBSTRUCTION_INTERVAL_MS) {
alarmOn();
}
else {
Expand Down Expand Up @@ -190,16 +190,27 @@ void alarmOff() {
}

void updateScreenIfRequired() {
if (updateDisplay) {
if (alarm) {
lcd.clear();
lcd.print("Beam obstructed!");
}
else if (state != DELAY) {
if (updateDisplay) {
if (state != DELAY) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Occupancy: ");
lcd.print(people, DEC);
}
}
if (alarm) {
lcd.setCursor(0,1);
lcd.print("Beam obstructed!");
} else if (beamInhibited) {
lcd.setCursor(0,1);
lcd.print("Beams disabled!");
} else {
lcd.setCursor(0,1);
if (lastIncrement > 0) {
lcd.print(" -->");
} else if (lastIncrement < 0) {
lcd.print("<-- ");
}
}

updateDisplay = false;
}
Expand Down Expand Up @@ -275,6 +286,12 @@ void processSerialInput() {
case 'X':
beamInhibit();
break;
case 'R':
people = 0;
lastIncrement = 0;
state = DELAY;
updateSerial = true;
break;
}
}
}
Expand Down

0 comments on commit 524045e

Please sign in to comment.