Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Code for the domestic installation of an overhead passenger service unit of an Avro RJ (British Aerospace 146) turbofan regional jet.
- Written: March 2021.
- Author: Sam Shelton [email protected]
- The PSU, originally configured to run on 28v, has been completely rewired to operate at around 5v. All original
- incandescent bulbs have been replaced by home-made LED parts. The original call bell light (which was non-functioning
- on delivery) has been replaced by a red/blue LED custom part.
- Additional features not present in the original installation include passenger control of;
- No smoking signs.
- Fasten seat belt signs.
- Blower fans.
- Oxygen mask deployment.
- V1.2: Improved button-press behaviour.
- */
- // ARDUINO PINOUT GUIDE
- // These constants are the connections for all our inputs and outputs:
- // Inputs Pins:
- const int inputPinButtonA = A0; // A-A0 // Short-Press toggles RLA, Long-press toggles No Smoking. GREEN CABLE
- const int inputPinButtonB = A1; // B-A1 // Short-Press toggles RLB, Long-press toggles blower. BLUE CABLE
- const int inputPinButtonC = A2; // C-A2 // Short-Press toggles RLC, Long-press toggles Fasten Seat Belts YELLOW CABLE
- const int inputPinButtonCallBell = A3; // // Short-Press toggles BLU, Long-press deploys oxygen masks. RED CABLE
- // Output Pins:
- const int outputPinLightCallBellBlue = 8; // This should be connected directly to '8BLU' on the call bell module.
- const int outputPinLightCallBellRed = 9 ; // This should be connected directly to '9RED' on the call bell module.
- const int outputPinMasks = 10; // This should be connected to the 'IN1/MSK' relay - THIS RELAY OPERATES ISOLATED 9V BATTERY / ACTUATOR ONLY
- const int outputPinChime = 11; // This should be connected to the the audio module.
- const int outputPinCabinNoise = 12; // This should be connected to the the audio module.
- const int outputPinlightReadingA = 2; // This should be connected to the 'IN2/RLA' relay. GREEN CABLE.
- const int outputPinlightReadingB = 3; // This should be connected to the 'IN3/RLB' relay. BLUE CABLE.
- const int outputPinlightReadingC = 4; // This should be connected to the 'IN4/RLC' relay. YELLOW CABLE.
- const int outputPinlightNoSmoking = 5; // This should be connected to the 'IN5/NS' relay. GREEN CABLE.
- const int outputPinlightSeatBelts = 6; // This should be connected to the 'IN6/FSB' relay. YELLOW CABLE.
- const int outputPinBlower = 7; // This should be connected to the 'IN7/BLW' relay. BLUE CABLE.
- // Still available to use: Input-only: A4, A5 Input OR Output: 13
- const unsigned int toggleTime = 1000; // the number of ms below which a light will not toggle on/off.
- const unsigned int longPressTime = 2000; // the number of ms
- const unsigned int maxLongPressTime = 3000; // for the purpose of the mask-drop system, the maximum long-press time.
- const unsigned int maskActiveTime = 500; // the number of ms that the mask release system stays active following an activation before resetting.
- const int startUpDelay = 250; // the number of ms the setup waits between switching things on when booting to reduce load.
- const int serialUpdateTime = 5000; // the number of ms between serial monitor updates, for readability.
- const unsigned long autoOffTime = 550000; // the number of ms before auto shutdown when party mode is not eanabled. (2 mins = 120000. 10 mins = 600000.)
- const unsigned long lengthOfAudioFile = 600000; // the number of ms that the audio file lasts for, so that we can restart it when it ends.
- // PRESSED/RELEASED STATE OF BUTTONS:
- // These bools store the on/off status of our inputs:
- bool buttonCallBell = 0; // Stores the current pressed (1)/ not-pressed (0) state of this button.
- bool buttonA = 0; // Stores the current pressed (1)/ not-pressed (0) state of this button.
- bool buttonB = 0; // Stores the current pressed (1)/ not-pressed (0) state of this button.
- bool buttonC = 0; // Stores the current pressed (1)/ not-pressed (0) state of this button.
- bool buttonCallBellActive = 0; // Stores a bool flagging whether this button has been pressed *and that action not yet processed*.
- bool buttonAActive = 0; // Stores a bool flagging whether this button has been pressed *and that action not yet processed*.
- bool buttonBActive = 0; // Stores a bool flagging whether this button has been pressed *and that action not yet processed*.
- bool buttonCActive = 0; // Stores a bool flagging whether this button has been pressed *and that action not yet processed*.
- // ON/OFF STATE OF LIGHTS AND EQUIPMENT:
- // These bools store the on/off status of our outputs:
- bool lightCallBellBlue = 0; // Stores the current on (1) / off (0) state of the blue call bell.
- bool lightCallBellRed = 0; // Stores the current on (1) / off (0) state of the red call bell. (NOT CURRENTLY IN USE)
- bool lightReadingA = 0; // Stores the current on (1) / off (0) state of reading light A.
- bool lightReadingB = 0; // Stores the current on (1) / off (0) state of reading light B.
- bool lightReadingC = 0; // Stores the current on (1) / off (0) state of reading light C.
- bool lightSeatBelts = 0; // Stores the current on (1) / off (0) state of the fasten seatbelt sign.
- bool lightNoSmoking = 0; // Stores the current on (1) / off (0) state of the no smoking sign.
- bool masks = 0; // Stores the current on (1) / off (0) state of mask deployment actuator.
- bool blower = 0; // Stores the current on (1) / off (0) state of the air blower.
- bool maskButtonReleaseActive = 0; // Stores the current on (1) / off (0) state of the mask button. When this is 1, releasing the button will activate the mask drop.
- bool partyMode = 0; // Stores the current on (1) / off (0) state of party mode.
- bool autoShutdownActivated = 0; // Stores the current on (1) / off (0) state of whether the unit is currently shut down by the auto shutdown function.
- unsigned long currentMillis; // stores the time at which the current loop started.
- unsigned long buttonALastOff; // stores the time at which buttonA was last in the 'off' state.
- unsigned long buttonBLastOff; // stores the time at which buttonB was last in the 'off' state.
- unsigned long buttonCLastOff; // stores the time at which buttonC was last in the 'off' state.
- unsigned long buttonCallBellLastOff; // stores the time at which buttonCallBell was last in the 'off' state.
- unsigned long audioRunning; // stores the length of time for which the audio track has been running.
- unsigned long lightReadingALastToggled; // stores the time at which lightReadingA was last toggled.
- unsigned long lightReadingBLastToggled; // stores the time at which lightReadingB was last toggled.
- unsigned long lightReadingCLastToggled; // stores the time at which lightReadingC was last toggled.
- unsigned long lightCallBellBlueLastToggled; // stores the time at which lightCallBellBlue was last toggled.
- unsigned long lightNoSmokingLastToggled; // stores the time at which lightNoSmoking was last toggled.
- unsigned long lightSeatBeltsLastToggled; // stores the time at which lightSeatBelts was last toggled.
- unsigned long blowerLastToggled; // stores the time at which the blower was last toggled.
- unsigned long partyModeLastToggled; // stores the time at which party mode was last toggled.
- unsigned long masksReleasedAt; // stores the time at which the mask panel was released.
- unsigned long serialUpdatedLast; // stores the time at which the serial monitor was last updated.
- unsigned long lastInputTime; // to make auto-shutdown work, the time at which there was last an input
- unsigned long timeToShutdown; // the number of seconds until autoShutdown;
- unsigned long audioRestartedLast; // stores the time at which the audio file was last restarted.
- void setup() { // This block of code runs only once, when the unit is switched on.
- Serial.begin(9600); // for troubleshooting, output a summary of current inputs and outputs,
- Serial.println(" "); // beginning with some sexy asterisk-surrounded shenanigans...
- Serial.println("********************************************************************************");
- Serial.println("* Passenger Service Unit *");
- Serial.println("* March 2021 *");
- Serial.println("* *");
- Serial.println("* Booting... *");
- Serial.println("****************************************-***************************************");
- // Set up the pins as outputs and inputs:
- pinMode (inputPinButtonCallBell, INPUT_PULLUP);
- pinMode (inputPinButtonA, INPUT_PULLUP);
- pinMode (inputPinButtonB, INPUT_PULLUP);
- pinMode (inputPinButtonC, INPUT_PULLUP);
- pinMode (outputPinLightCallBellBlue, OUTPUT);
- pinMode (outputPinLightCallBellRed, OUTPUT);
- pinMode (outputPinlightReadingA, OUTPUT);
- pinMode (outputPinlightReadingB, OUTPUT);
- pinMode (outputPinlightReadingC, OUTPUT);
- pinMode (outputPinlightSeatBelts, OUTPUT);
- pinMode (outputPinlightNoSmoking, OUTPUT);
- pinMode (outputPinMasks, OUTPUT);
- pinMode (outputPinBlower, OUTPUT);
- pinMode (outputPinChime, OUTPUT);
- pinMode (outputPinCabinNoise, OUTPUT);
- // Configure settings for when the PSU is booted:
- digitalWrite(outputPinChime, HIGH);
- digitalWrite(outputPinCabinNoise, HIGH);
- lightCallBellRed = 1;
- lightCallBellBlue = 0;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- lightCallBellRed = 0;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 1;
- lightReadingA = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- lightReadingB = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 1;
- lightReadingC = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- lightSeatBelts = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 1;
- lightNoSmoking = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- masks = 0;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- blower = 1;
- switchOutputs();
- delay(startUpDelay);
- lightCallBellRed = 0;
- startCabinNoise();
- lastInputTime = millis();
- }
- void loop() { // These subroutines run thousands of times a second.
- currentMillis = millis(); // Take note of the time at which this loop started.
- readInputs(); // Find out what buttons are pressed.
- process(); // Figure out what to do with all of those inputs.
- switchOutputs(); // Switch LEDS and relays on and off as necessary.
- updateSerial(); // Update a serial monitor for troubleshooting.
- maskReset(); // Monitor the status of the mask deployment actuator and reset it when necessary.
- maskDropTimer(); // Run the red flashing light during call-bell long-press, and activate mask drop.
- switchPartyMode(); // Check whether buttons A and B are pressed simultaneously, toggling party mode and confirming with lights.
- autoShutdown(); // Check to see whether it's time to shut down the unit during normal operation (i.e. party mode is not enabled)
- restartAudio(); // If the audio file is nearly finished, restart it - as long as the unit hasn't shut down.
- restartAfterShutdown(); // while the unit is shutdown, monitor the buttons and 'wake up' if one of them is pressed.
- // delay(200) ; // DURING TESTING ONLY: SLOW EVERYTHING DOWN A BIT SO WE DON'T BREAK ANYTHING!
- }
- void restartAudio() { // If the audio file is nearly finished, restart it - as long as the unit hasn't shut down.
- if (currentMillis - audioRestartedLast > lengthOfAudioFile && autoShutdownActivated == 0) { // If the lengthOfAudioFile has past, and the unit hasn't shut down...
- startCabinNoise(); // Restart the cabin noise track from the start.
- }
- }
- void restartAfterShutdown() { // while the unit is shutdown, monitor the buttons and 'wake up' if one of them is pressed.
- if (autoShutdownActivated == 1) { // if the unit is currently shut down...
- if (buttonCallBell || buttonA || buttonB || buttonC ) // and if one the buttons is pressed...
- {
- autoShutdownActivated = 0; // set the autoShutdownActivated flag to 0.
- startCabinNoise(); // Restart the cabin noise track from the start.
- lightNoSmoking = 1; // Switch the no smoking light on.
- lightSeatBelts = 1; // Switch the seat belt light on.
- }
- }
- }
- void readInputs() { // Find out what buttons are pressed.
- buttonCallBell = !digitalRead(inputPinButtonCallBell); // If this button is 'LOW' (remember we're using a pullup resistor) then set the relevant status to 'HIGH'.
- buttonA = !digitalRead(inputPinButtonA); // If this button is 'LOW' (remember we're using a pullup resistor) then set the relevant status to 'HIGH'.
- buttonB = !digitalRead(inputPinButtonB); // If this button is 'LOW' (remember we're using a pullup resistor) then set the relevant status to 'HIGH'.
- buttonC = !digitalRead(inputPinButtonC); // If this button is 'LOW' (remember we're using a pullup resistor) then set the relevant status to 'HIGH'.
- }
- void process() { // Figure out what to do with all of those inputs.
- // PROCESS FOR CALL BELL BUTTON **********************************************************************************************
- if (buttonCallBell) { // if the button is pressed...
- buttonCallBellActive = 1; // set the 'active' status of this button to 1
- lastInputTime = currentMillis; // set the last input time to now.
- };
- if (buttonCallBellActive && !buttonCallBell) { // if the status is 'active' and the button has now been released...
- if (currentMillis - lightCallBellBlueLastToggled > toggleTime && currentMillis - buttonCallBellLastOff < longPressTime) { // if it was a short-press, and the light hasn't just been already toggled.
- if (lightCallBellBlue == 0) { // if the call bell light is currently off (We only want it to chime when it goes from OFF to ON, and not the other way around.)
- startCabinChime(); // start the cabin sound track that starts with a chime.
- }
- lightCallBellBlue = !lightCallBellBlue; // toggle the light
- lightCallBellBlueLastToggled = currentMillis; // and take note of the time it was toggled.
- }
- if (maskButtonReleaseActive == 1) { // if it was a long-press:
- masks = 1; // set the mask release flag to 1
- masksReleasedAt = currentMillis; // take note of the time it was done.
- ("The masks were deployed");
- }
- buttonCallBellActive = 0; // otherwise, ignore the fact the button was pressed and released.
- }
- if (!buttonCallBell) { // if the button is not pressed...
- buttonCallBellLastOff = currentMillis; // take note of the time (now) that it was last not pressed.
- buttonCallBellActive = 0; // and set the active flag back to 0.
- }
- // PROCESS FOR READING LIGHT A BUTTON *****************************************************************************************
- if (buttonA) { // if the button is pressed...
- buttonAActive = 1; // set the 'active' status of this button to 1
- lastInputTime = currentMillis; // set the last input time to now.
- };
- if (buttonAActive && !buttonA) { // if the status is 'active' and the button has now been released...
- if (currentMillis - lightReadingALastToggled > toggleTime && currentMillis - buttonALastOff < longPressTime) { // if it was a short-press, and the light hasn't just been already toggled.
- lightReadingA = !lightReadingA; // toggle the light
- lightReadingALastToggled = currentMillis; // and take note of the time it was toggled.
- buttonAActive = 0; // and set the active flag back to 0.
- }
- }
- if (buttonAActive && currentMillis - buttonALastOff > longPressTime && currentMillis - lightNoSmokingLastToggled > toggleTime) { // if it was a long-press and the light hasn't been toggled recently.
- Serial.println("Toggling No Smoking Light");
- lightNoSmoking = !lightNoSmoking; // toggle the light.
- lightNoSmokingLastToggled = currentMillis; // and take note of the time it was toggled.
- buttonAActive = 0; // and set the active flag back to 0.
- }
- if (!buttonA) { // if the button is not pressed...
- buttonALastOff = currentMillis; // take note of the time (now) that it was last not pressed.
- buttonAActive = 0; // and set the active flag back to 0.
- }
- // PROCESS FOR READING LIGHT B BUTTON *****************************************************************************************
- if (buttonB) { // if the button is pressed...
- buttonBActive = 1; // set the 'active' status of this button to 1
- lastInputTime = currentMillis; // set the last input time to now.
- };
- if (buttonBActive && !buttonB) { // if the status is 'active' and the button has now been released...
- if (currentMillis - lightReadingBLastToggled > toggleTime && currentMillis - buttonBLastOff < longPressTime) { // if it was a short-press, and the light hasn't just been already toggled.
- lightReadingB = !lightReadingB; // toggle the light
- lightReadingBLastToggled = currentMillis; // and take note of the time it was toggled.
- buttonBActive = 0; // otherwise, ignore the fact the button was pressed and released.
- }
- }
- if (buttonBActive && currentMillis - buttonBLastOff > longPressTime && currentMillis - blowerLastToggled > toggleTime) { // if it was a long-press and the light hasn't been toggled recently.
- blower = !blower; // toggle the light.
- blowerLastToggled = currentMillis; // and take note of the time it was toggled.
- buttonBActive = 0; // otherwise, ignore the fact the button was pressed and released.
- }
- if (!buttonB) { // if the button is not pressed...
- buttonBLastOff = currentMillis; // take note of the time (now) that it was last not pressed.
- buttonBActive = 0; // and set the active flag back to 0.
- }
- // PROCESS FOR READING LIGHT C BUTTON *****************************************************************************************
- if (buttonC) { // if the button is pressed...
- buttonCActive = 1; // set the 'active' status of this button to 1
- lastInputTime = currentMillis; // set the last input time to now.
- };
- if (buttonCActive && !buttonC) { // if the status is 'active' and the button has now been released...
- if (currentMillis - lightReadingCLastToggled > toggleTime && currentMillis - buttonCLastOff < longPressTime) { // if it was a short-press, and the light hasn't just been already toggled.
- lightReadingC = !lightReadingC; // toggle the light
- lightReadingCLastToggled = currentMillis; // and take note of the time it was toggled.
- buttonCActive = 0; // otherwise, ignore the fact the button was pressed and released.
- }
- }
- if (buttonCActive && currentMillis - buttonCLastOff > longPressTime && currentMillis - lightSeatBeltsLastToggled > toggleTime) { // if it was a long-press and the light hasn't been toggled recently.
- lightSeatBelts = !lightSeatBelts; // toggle the light.
- lightSeatBeltsLastToggled = currentMillis; // and take note of the time it was toggled.
- buttonCActive = 0; // otherwise, ignore the fact the button was pressed and released.
- }
- if (!buttonC) { // if the button is not pressed...
- buttonCLastOff = currentMillis; // take note of the time (now) that it was last not pressed.
- buttonCActive = 0; // and set the active flag back to 0.
- }
- }// end of process
- void switchOutputs() { // Switch LEDS and relays on and off as necessary.
- digitalWrite(outputPinlightReadingA, !lightReadingA);
- digitalWrite(outputPinlightReadingB, !lightReadingB);
- digitalWrite(outputPinlightReadingC, !lightReadingC);
- digitalWrite(outputPinLightCallBellBlue, lightCallBellBlue);
- digitalWrite(outputPinLightCallBellRed, lightCallBellRed);
- digitalWrite(outputPinMasks, !masks);
- digitalWrite(outputPinlightNoSmoking , !lightNoSmoking);
- digitalWrite(outputPinlightSeatBelts , !lightSeatBelts);
- digitalWrite(outputPinBlower , !blower);
- }
- void maskReset() { // if the mask panel actuator has been triggered, reset it after maskActiveTime so that it can be manually reset.
- if (masks == 1 && currentMillis - masksReleasedAt > maskActiveTime) {
- masks = 0;
- Serial.println("The masks were reset");
- }
- }
- void startCabinNoise() { // Restart the cabin noise track from the start.
- Serial.println("startCabinNoise()");
- digitalWrite(outputPinCabinNoise , LOW); // Set the cabin noise pin to low (this triggers the track playing).
- delay(200); // Wait a moment.
- digitalWrite(outputPinCabinNoise , HIGH); // Set the cabin noise pin back to high (ready to be reacivated when necessary).
- audioRestartedLast = currentMillis; // For the purpose of restarting the track when it's finished (restartAudio()), take note of the time.
- }
- void startCabinChime() { // Restart the cabin noise track 'that starts with a chime' from the start.
- Serial.println("startCabinChime()");
- digitalWrite(outputPinChime , LOW); // Set the cabin noise pin to low (this triggers the track playing).
- delay(200); // Wait a moment.
- digitalWrite(outputPinChime , HIGH); // Set the cabin noise pin back to high (ready to be reacivated when necessary).
- audioRestartedLast = currentMillis; // For the purpose of restarting the track when it's finished (restartAudio()), take note of the time.
- }
- void maskDropTimer() { // Run the red flashing light during call-bell long-press, and activate mask drop.
- if ((currentMillis - buttonCallBellLastOff > 500 && currentMillis - buttonCallBellLastOff < 1000) ||
- (currentMillis - buttonCallBellLastOff > 1500 && currentMillis - buttonCallBellLastOff < 2000) ||
- (currentMillis - buttonCallBellLastOff > 2500 && currentMillis - buttonCallBellLastOff < 3000)) { // if the call bell flashing sequence is in it's 'on' phase...
- lightCallBellRed = 1; // turn lightCallBellRed to 'on'.
- } else { // else
- lightCallBellRed = 0; // turn lightCallBellRed to 'off'.
- }
- if (currentMillis - buttonCallBellLastOff > 3500 && currentMillis - buttonCallBellLastOff < 4000) { // if the call bell flashing sequence is in it's fourth 'on' phase...
- lightCallBellRed = 1; // turn lightCallBellRed to 'on'.
- maskButtonReleaseActive = 1; // and set maskButtonReleaseActive to on, meaning that releasing it during this phase will drop the masks
- } else { // else
- maskButtonReleaseActive = 0; // leave maskButtonReleaseActive off.
- }
- }
- void switchPartyMode() { // Check whether buttons A and B are pressed simultaneously, toggling party mode and confirming with lights.
- if (buttonA && buttonB && partyMode) { // if buttons A and B are pressed, and party mode is currently set to on,
- Serial.println("Party Mode OFF");
- digitalWrite(outputPinlightReadingA, 0); // flash the lights alternately.
- digitalWrite(outputPinlightReadingB, 0);
- digitalWrite(outputPinlightReadingC, 0);
- delay(500);
- digitalWrite(outputPinlightReadingA, 1);
- digitalWrite(outputPinlightReadingB, 1);
- digitalWrite(outputPinlightReadingC, 1);
- delay(500);
- digitalWrite(outputPinlightReadingA, 0);
- digitalWrite(outputPinlightReadingB, 0);
- digitalWrite(outputPinlightReadingC, 0);
- delay(500);
- partyModeLastToggled = currentMillis; // take note of the current time to debounce party mode.
- partyMode = 0; // set party mode to 'off'
- everythingOff(); // turn everything off.
- }
- if (buttonA && buttonB && !partyMode) { // if buttons A and B are pressed, and party mode is currently set to off.
- Serial.println("Party Mode ON");
- digitalWrite(outputPinlightReadingA, 0); // flash the lights together.
- digitalWrite(outputPinlightReadingB, 1);
- digitalWrite(outputPinlightReadingC, 0);
- delay(500);
- digitalWrite(outputPinlightReadingA, 1);
- digitalWrite(outputPinlightReadingB, 0);
- digitalWrite(outputPinlightReadingC, 1);
- delay(500);
- digitalWrite(outputPinlightReadingA, 0);
- digitalWrite(outputPinlightReadingB, 1);
- digitalWrite(outputPinlightReadingC, 0);
- delay(500);
- partyModeLastToggled = currentMillis; // take note of the current time to debounce party mode.
- partyMode = 1; // set party mode to 'on'.
- everythingOn(); // turn everything on.
- }
- }
- void everythingOff() { // what to do when we 'turn everything off'.
- Serial.println("Turning everything OFF");
- lightCallBellBlue = 0;
- lightCallBellRed = 0;
- lightReadingA = 0;
- lightReadingB = 0;
- lightReadingC = 0;
- lightSeatBelts = 0;
- lightNoSmoking = 0;
- blower = 0;
- buttonA = 0;
- buttonB = 0;
- buttonC = 0;
- buttonAActive = 0;
- buttonBActive = 0;
- buttonCActive = 0;
- }
- void everythingOn() { // what to do when we 'turn everything on'.
- Serial.println("Turning everything ON");
- lightCallBellBlue = 0;
- lightCallBellRed = 0;
- lightReadingA = 1;
- lightReadingB = 1;
- lightReadingC = 1;
- lightSeatBelts = 1;
- lightNoSmoking = 1;
- blower = 1;
- buttonA = 0;
- buttonB = 0;
- buttonC = 0;
- buttonAActive = 0;
- buttonBActive = 0;
- buttonCActive = 0;
- }
- void updateSerial() { // Update a serial monitor for troubleshooting.
- if (currentMillis - serialUpdatedLast > serialUpdateTime) {
- // Button states:
- Serial.print("Buttons A");
- Serial.print(buttonA);
- Serial.print(" B");
- Serial.print(buttonB);
- Serial.print(" C ");
- Serial.print(buttonC);
- Serial.print(" Call ");
- Serial.print(buttonCallBell);
- // Equipment states:
- Serial.print(" BLU:");
- Serial.print(lightCallBellBlue);
- Serial.print(" RED:");
- Serial.print(lightCallBellRed);
- Serial.print(" RL A");
- Serial.print(lightReadingA);
- Serial.print(" B");
- Serial.print(lightReadingB);
- Serial.print(" C");
- Serial.print(lightReadingC);
- Serial.print(" FSB:");
- Serial.print(lightSeatBelts);
- Serial.print(" NS:");
- Serial.print(lightNoSmoking);
- Serial.print(" MSK:");
- Serial.print(masks);
- Serial.print(" BLW:");
- Serial.print(blower);
- Serial.print(" Party:");
- Serial.print(partyMode);
- // System up-time:
- Serial.print(" UP: ");
- Serial.print(abs(currentMillis / 86400000));
- Serial.print("d ");
- Serial.print(abs(currentMillis / 3600000) - abs(currentMillis / 86400000) * 24);
- Serial.print("h ");
- Serial.print(abs(currentMillis / 60000) - (abs(currentMillis / 3600000) * 60));
- Serial.print("m ");
- Serial.print((currentMillis / 1000) - (abs(currentMillis / 60000) * 60));
- Serial.print ("s");
- // Autoshutdown:
- if (partyMode == 0) {
- Serial.print(" Auto-shutdown in: ");
- Serial.print(timeToShutdown);
- } else {
- Serial.print(" Party Mode enabled.");
- }
- Serial.println(""); // start a new line:
- serialUpdatedLast = currentMillis;
- }
- }
- void autoShutdown() { // Check to see whether it's time to shut down the unit during normal operation (i.e. party mode is not enabled).
- if (partyMode == 0) { // if party mode is currently set to 'off'.
- if (((autoOffTime - (currentMillis - lastInputTime)) / 1000) > 400000) { // If the 'time to shut-down isn't an erroneously high number.
- timeToShutdown = (autoOffTime / 1000); // set timeToShutdown to the autoOffTime in seconds.
- } else { // else (if it's an erroneously high number)
- timeToShutdown = (autoOffTime - (currentMillis - lastInputTime)) / 1000; // set it to the number of seconds till shutdown.
- }
- }
- if (timeToShutdown < 1) { // if the timeToShutdown is under 1 second...
- lastInputTime = currentMillis; // set the last input time to now
- everythingOff(); // turn everything off.
- autoShutdownActivated = 1; // activate shutdown mode.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment