Hardware Reference
In-Depth Information
timeLastPressed = millis();
blockSteps = 0;
houseState = 0;
}
void loop() {
int pinState = digitalRead(inputSwitchPin);
if (pinState != lastState && millis() - timeLastPressed > debouncePeriod) {
if (pinState == 0) { // i.e., pressed
if (!blockSteps) {
houseState = 1-houseState;
blockSteps = 1;
Serial.print(houseState?"1":"0");
}
doormatUnblockAt = millis() + doormatDelayPeriod;
}
timeLastPressed = millis();
lastState = pinState;
}
if (millis() > doormatUnblockAt) {
blockSteps = 0;
}
}
Finally, the USB script trigger code shown previously is adapted to watch for the serial messages of 0 and 1:
if (v == '1') {
system("enter_house.sh");
} else if (v == '0') {
system("leave_house.sh");
... as before ...
which runs either the enter_house.sh script for entering:
say default welcome home
x10control default on lounge_light
or the leave_house.sh script for leaving as appropriate:
say default Goodbye
RAIN=`weatherstatus | head -n 1 | grep -i "[rain|shower]"`
if [ "$?" -eq 0 ]; then
say default Remember your umbrella it might rain today.
say default $RAIN
fi
In these code samples, I have used simplified commands without paths to demonstrate the process.
The commands themselves are the abstractions that appear in the Minerva system, covered in Chapter 7.
Search WWH ::




Custom Search