/* ShiftDisplay.cpp - Shift Display Class Implementation File */ #include "ShiftDisplay.h" /* ShiftDisplay - Default Constructor ShiftDisplay () Creates a new ShiftDisplay initializing the use of A0 for the clock pin and A1 for the data pin. */ ShiftDisplay::ShiftDisplay () { begin(DEFAULT_CLOCK, DEFAULT_DATA); } /* ShiftDisplay - Constructor with Parameters ShiftDisplay (byte clock, byte data) Creates a new ShiftDisplay initializing the clock and data pins as specified. */ ShiftDisplay::ShiftDisplay (byte clock, byte data) { begin(clock, data); } /* begin - Initialization void begin (byte clock, byte data) Initializes the specified clock and data output pins. */ void ShiftDisplay::begin (byte clock, byte data) { setClock(clock); setData(data); } /* setClock - Set Clock Pin Number void setClock (byte clock) Sets the specified clock pin number and initializes it as an output. */ void ShiftDisplay::setClock (byte clock) { _clock = clock; pinMode(_clock, OUTPUT); } /* getClock - Get Clock Pin Number byte getClock () Returns the clock pin number used for this display. */ byte ShiftDisplay::getClock () { return _clock; } /* setData - Set Data Pin Number void setData (byte data) Sets the specified data pin number and initializes it as an output. */ void ShiftDisplay::setData (byte data) { _data = data; pinMode(_data, OUTPUT); } /* getData - Get Data Pin Number byte getData () Returns the data pin number used for this display. */ byte ShiftDisplay::getData () { return _data; } /* setHexOne - Enable/disable One Digit Hex Mode void setHexOne (bool hex) Turns the hexadecimal mode for the one digit display on or off as specified. */ void ShiftDisplay::setHexOne (bool hex) { if (hex) { SET_OPTION_HEXONE; } else { CLR_OPTION_HEXONE; } } /* isHexOne - Test One Digit Hex Mode bool isHexOne () Returns true if the one digit hexadecimal display mode is enabled. */ bool ShiftDisplay::isHexOne () { return IS_OPTION_HEXONE; } /* setHexTwo - Enable/disable Two Digit Hex Mode void setHexTwo (bool hex) Turns the hexadecimal mode for the two digit display on or off as specified. */ void ShiftDisplay::setHexTwo (bool hex) { if (hex) { SET_OPTION_HEXTWO; } else { CLR_OPTION_HEXTWO; } } /* isHexTwo - Test Two Digit Hex Mode bool isHexTwo () Returns true if the two digit hexadecimal display mode is enabled. */ bool ShiftDisplay::isHexTwo () { return IS_OPTION_HEXTWO; } /* setDP1 - Enable/disable Decimal Point 1 void setDP1 (bool dp1) Turns the first decimal point option on or off as specified. The display is not updated by this function. The first decimal point is the one on the one digit display. */ void ShiftDisplay::setDP1 (bool dp1) { if (dp1) { SET_OPTION_DP1; } else { CLR_OPTION_DP1; } } /* isDP1 - Test Decimal Point 1 Enabled bool isDP1 () Returns true if the decimal point 1 option is enabled. */ bool ShiftDisplay::isDP1 () { return IS_OPTION_DP1; } /* setDP2 - Enable/disable Decimal Point 2 void setDP2 (bool dp2) Turns the second decimal point option on or off as specified. The display is not updated by this function. The second decimal point is the one on the higher order digit of the two digit display group. */ void ShiftDisplay::setDP2 (bool dp2) { if (dp2) { SET_OPTION_DP2; } else { CLR_OPTION_DP2; } } /* isDP2 - Test Decimal Point 2 Enabled bool isDP2 () Returns true if the decimal point 2 option is enabled. */ bool ShiftDisplay::isDP2 () { return IS_OPTION_DP2; } /* setDP3 - Enable/disable Decimal Point 3 void setDP3 (bool dp3) Turns the third decimal point option on or off as specified. The display is not updated by this function. The third decimal point is the one on the lower order digit of the two digit display group. */ void ShiftDisplay::setDP3 (bool dp3) { if (dp3) { SET_OPTION_DP3; } else { CLR_OPTION_DP3; } } /* isDP3 - Test Decimal Point 3 Enabled bool isDP3 () Returns true if the decimal point 3 option is enabled. */ bool ShiftDisplay::isDP3 () { return IS_OPTION_DP3; } /* setBlankOne - Enable/disable One Digit Blank Mode void setBlankOne (bool blank) Use this option to blank the one digit display. The display is not updated by this function. With this option enabled, the next display output will clear the one digit display. The current value of the one digit display is not modified. The flash option is disabled when blank mode is enabled. */ void ShiftDisplay::setBlankOne (bool blank) { if (blank) { SET_OPTION_BLANKONE; CLR_OPTION_FLASHONE; } else { CLR_OPTION_BLANKONE; } } /* isBlankOne - Test One Digit Blank Mode bool isBlankOne () Returns true if the one digit display blank mode is enabled. */ bool ShiftDisplay::isBlankOne () { return IS_OPTION_BLANKONE; } /* setBlankTwo - Enable/disable Two Digit Blank Mode void setBlankTwo (bool blank) Use this option to blank the two digit display. The display is not updated by this function. With this option enabled, the next display output will clear the two digit display. The current value of the two digit display is not modified. The flash option is disabled when blank mode is enabled. */ void ShiftDisplay::setBlankTwo (bool blank) { if (blank) { SET_OPTION_BLANKTWO; CLR_OPTION_FLASHTWO; } else { CLR_OPTION_BLANKTWO; } } /* isBlankTwo - Test Two Digit Blank Mode bool isBlankTwo () Returns true if the two digit blank mode is enabled. */ bool ShiftDisplay::isBlankTwo () { return IS_OPTION_BLANKTWO; } /* setSLZero - Enable/Disable Suppress Leading Zero void setSLZero (bool slzero) Set this option to suppress the leading zero on the two digit display. */ void ShiftDisplay::setSLZero (bool slzero) { if (slzero) { SET_OPTION_SLZERO; } else { CLR_OPTION_SLZERO; } } /* isSLZero - Test the Suppress Leading Zero Option bool isSLZero () Returns true if the suppress leading zero option is enabled. */ bool ShiftDisplay::isSLZero () { return IS_OPTION_SLZERO; } /* setOnTimeOne - Set On Time for One Digit Flashing void setOnTimeOne (int onTime) Sets the number of milliseconds that the one digit display remains on while flashing. */ void ShiftDisplay::setOnTimeOne (int onTime) { _onTimeOne = onTime; } /* getOnTimeOne - Get On Time for One Digit Flashing int getOnTimeOne () Returns the number of milliseconds that the one digit display remains on while flashing. */ int ShiftDisplay::getOnTimeOne () { return _onTimeOne; } /* setOffTimeOne - Set Off Time for One Digit Flashing void setOffTimeOne (int offTime) Sets the number of milliseconds that the one digit display remains off while flashing. */ void ShiftDisplay::setOffTimeOne (int offTime) { _offTimeOne = offTime; } /* getOffTimeOne - Get Off Time for One Digit Flashing int getOffTimeOne () Returns the number of milliseconds that the one digit display remains off while flashing. */ int ShiftDisplay::getOffTimeOne () { return _offTimeOne; } /* setOnTimeTwo - Set On Time for Two Digit Flashing void setOnTimeTwo (int onTime) Sets the number of milliseconds that the two digit display remains on while flashing. */ void ShiftDisplay::setOnTimeTwo (int onTime) { _onTimeTwo = onTime; } /* getOnTimeTwo - Get On Time for Two Digit Flashing int getOnTimeTwo () Returns the number of milliseconds that the two digit display remains on while flashing. */ int ShiftDisplay::getOnTimeTwo () { return _onTimeTwo; } /* setOffTimeTwo - Set Off Time for Two Digit Flashing void setOffTimeTwo (int offTime) Sets the number of milliseconds that the two digit display remains off while flashing. */ void ShiftDisplay::setOffTimeTwo (int offTime) { _offTimeTwo = offTime; } /* getOffTimeTwo - Get Off Time for Two Digit Flashing int getOffTimeTwo () Returns the number of milliseconds that the two digit display remains off while flashing. */ int ShiftDisplay::getOffTimeTwo () { return _offTimeTwo; } /* flashOne - Flash New One Digit Value void flashOne (byte one) Flashes the specified value on the one digit display. The value overwrites any previous value for the one digit display. The new value is output and the flash timer begins. */ void ShiftDisplay::flashOne (byte one) { _one = one; flashOne(); } /* flashOne - Flash Current One Digit Value void flashOne () Flashes the current value on the one digit display. The value is output and the flash timer begins. */ void ShiftDisplay::flashOne () { SET_OPTION_FLASHONE; CLR_OPTION_BLANKONE; _timerOne = millis(); out(); } /* flashTwo - Flash New Two Digit Value void flashTwo (byte two) Flashes the specified value on the two digit display. The value overwrites any previous value for the two digit display. The new value is output and the flash timer begins. */ void ShiftDisplay::flashTwo (byte two) { _two = two; flashTwo(); } /* flashTwo - Flash Current Two Digit Value void flashTwo () Flashes the current value on the two digit display. The value is output and the flash timer begins. */ void ShiftDisplay::flashTwo () { SET_OPTION_FLASHTWO; CLR_OPTION_BLANKTWO; _timerTwo = millis(); out(); } /* update - Update for Flashing void update (ULONG now) This function is called repeatedly to update the timing of any flashing operations. The current time in milliseconds is specified as obtained from the "millis" function. If no flashing is required, this function need not be utilized. */ void ShiftDisplay::update (ULONG now) { if (IS_OPTION_FLASHONE) { if (IS_OPTION_BLANKONE) { if (now - _timerOne >= _offTimeOne) { _timerOne = now; CLR_OPTION_BLANKONE; out(); } } else { if (now - _timerOne >= _onTimeOne) { _timerOne = now; SET_OPTION_BLANKONE; out(); } } } if (IS_OPTION_FLASHTWO) { if (IS_OPTION_BLANKTWO) { if (now - _timerTwo >= _offTimeTwo) { _timerTwo = now; CLR_OPTION_BLANKTWO; out(); } } else { if (now - _timerTwo >= _onTimeTwo) { _timerTwo = now; SET_OPTION_BLANKTWO; out(); } } } } /* setOne - Set One Digit Value void setOne (byte one) Use this function to set the specified value for the one digit display. The value is not output. */ void ShiftDisplay::setOne (byte one) { _one = one; } /* getOne - Get One Digit Value byte getOne () Use this function to obtain the current one digit display value. */ byte ShiftDisplay::getOne () { return _one; } /* setTwo - Set Two Digit Value void setTwo (byte two) Use this function to set the specified value for the two digit display. The value is not output. */ void ShiftDisplay::setTwo (byte two) { _two = two; } /* getTwo - Get Two Digit Value byte getTwo () Use this function to obtain the current two digit display value. */ byte ShiftDisplay::getTwo () { return _two; } /* outOne - Output One Digit Value void outOne (byte one) Sets the specified value for the one digit display and outputs this value. Both blanking and flashing of the one digit display is cancelled. */ void ShiftDisplay::outOne (byte one) { _one = one; CLR_OPTION_BLANKONE; CLR_OPTION_FLASHONE; out(); } /* outTwo - Output Two Digit Value void outTwo (byte two) Sets the specified value for the two digit display and outputs this value. Both blanking and flashing options of the two digit display are cancelled. */ void ShiftDisplay::outTwo (byte two) { _two = two; CLR_OPTION_BLANKTWO; CLR_OPTION_FLASHTWO; out(); } /* out - Output Current Values void out () Outputs the current values for both the one digit and two digit displays. If any blanking modes are enabled, a blank display code is sent. If hexadecimal modes are enabled, hex codes may be sent. Decimal point options are also evaluated to send the appropriate codes for their display. */ void ShiftDisplay::out () { byte one = 0; byte two = 0; byte divisor = 10; if (! IS_OPTION_BLANKONE) { if (IS_OPTION_HEXONE) { divisor = 0x10; } one = _one % divisor; one = _segments[one]; } if (IS_OPTION_DP1) { ++one; } shift(one); if (! IS_OPTION_BLANKTWO) { divisor = 10; if (IS_OPTION_HEXTWO) { divisor = 0x10; } two = (_two / divisor) % divisor; if ((! IS_OPTION_SLZERO) || (two != 0)) { two = _segments[two]; } } if (IS_OPTION_DP2) { ++two; } shift(two); two = 0; if (! IS_OPTION_BLANKTWO) { two = _two % divisor; two = _segments[two]; } if (IS_OPTION_DP3) { ++two; } shift(two); } /* out - Output New Values void out (byte one, byte two) Sets new values for both the one digit and two digit display groups and outputs these values to the display. Any blanking options are cancelled. Flashing remains operational. */ void ShiftDisplay::out (byte one, byte two) { _one = one; _two = two; CLR_OPTION_BLANKONE; CLR_OPTION_BLANKTWO; out(); } /* shift - Output Byte to Shift Register void shift (byte value) Outputs the specified 8 bit value to the shift register. */ void ShiftDisplay::shift (byte value) { shiftOut(_data, _clock, MSBFIRST, value); }