Permalink
Browse files

Reset command, display last event on LCD.

  • Loading branch information...
teabot committed Feb 4, 2011
1 parent 1ad163a commit 524045ea6c1e71dee091e181211e86502ed5e8e2
Showing with 28 additions and 10 deletions.
  1. +1 −0 README
  2. +27 −10 spacensus.pde
View
1 README
@@ -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:
View
@@ -63,6 +63,7 @@ void setup()
pinMode(BEAM_IN, INPUT);
pinMode(BEAM_OUT, INPUT);
+ lcd.begin(16, 2);
lcd.print("spacensus v0.1");
}
@@ -126,7 +127,6 @@ void handleBeamBreak(int interrupt, int gotoState, int waitingForState, int incr
updateSerial = true;
}
state = DELAY;
-
}
}
@@ -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 {
@@ -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;
}
@@ -275,6 +286,12 @@ void processSerialInput() {
case 'X':
beamInhibit();
break;
+ case 'R':
+ people = 0;
+ lastIncrement = 0;
+ state = DELAY;
+ updateSerial = true;
+ break;
}
}
}

0 comments on commit 524045e

Please sign in to comment.