/* ShiftDisplay.h - Shift Display Class Header File This class makes use of 3 shift registers that are cascaded to drive 3 seven segment LED displays using just 2 pins from the Arduino microprocessor. The displays are grouped as one digit and another as two digits. There are functions to manipulate these two groups independently. Initialization requires specification of the clock and data output pins to the shift registers. These can be any of the Arduino pins; either Analog or Digital. The default display mode is decimal for both the one and two digit groupings. There are options to change to hexidecimal display for each of these. Decimal points can be enabled and disabled for each of the display digits. The first of these is for the one digit display. The second is for the higher order digit of the two digit display. And the third decimal point is for the lower order digit of the two digit display. These options do not change the display until the next output request is made. Blanking of the display groups is also supported. Again, these options do not change the display until an output request is made. */ #ifndef ShiftDisplay_h #define ShiftDisplay_h #include #include "Types.h" #define DEFAULT_CLOCK A0 #define DEFAULT_DATA A1 static byte _segments [] = { 0b11111100, // 0 0b01100000, // 1 0b11011010, // 2 0b11110010, // 3 0b01100110, // 4 0b10110110, // 5 0b10111110, // 6 0b11100000, // 7 0b11111110, // 8 0b11110110, // 9 0b11101110, // A 0b00111110, // b 0b10011100, // C 0b01111010, // d 0b10011110, // E 0b10001110 // F }; #define OPTION_HEXONE 1 #define OPTION_HEXTWO 2 #define OPTION_DP1 4 #define OPTION_DP2 8 #define OPTION_DP3 16 #define OPTION_BLANKONE 32 #define OPTION_BLANKTWO 64 #define OPTION_FLASHONE 128 #define OPTION_FLASHTWO 256 #define OPTION_SLZERO 512 #define SET_OPTION_HEXONE (_option |= OPTION_HEXONE) #define CLR_OPTION_HEXONE (_option &= ~OPTION_HEXONE) #define IS_OPTION_HEXONE (_option & OPTION_HEXONE) #define SET_OPTION_HEXTWO (_option |= OPTION_HEXTWO) #define CLR_OPTION_HEXTWO (_option &= ~OPTION_HEXTWO) #define IS_OPTION_HEXTWO (_option & OPTION_HEXTWO) #define SET_OPTION_DP1 (_option |= OPTION_DP1) #define CLR_OPTION_DP1 (_option &= ~OPTION_DP1) #define IS_OPTION_DP1 (_option & OPTION_DP1) #define SET_OPTION_DP2 (_option |= OPTION_DP2) #define CLR_OPTION_DP2 (_option &= ~OPTION_DP2) #define IS_OPTION_DP2 (_option & OPTION_DP2) #define SET_OPTION_DP3 (_option |= OPTION_DP3) #define CLR_OPTION_DP3 (_option &= ~OPTION_DP3) #define IS_OPTION_DP3 (_option & OPTION_DP3) #define SET_OPTION_BLANKONE (_option |= OPTION_BLANKONE) #define CLR_OPTION_BLANKONE (_option &= ~OPTION_BLANKONE) #define IS_OPTION_BLANKONE (_option & OPTION_BLANKONE) #define SET_OPTION_BLANKTWO (_option |= OPTION_BLANKTWO) #define CLR_OPTION_BLANKTWO (_option &= ~OPTION_BLANKTWO) #define IS_OPTION_BLANKTWO (_option & OPTION_BLANKTWO) #define SET_OPTION_FLASHONE (_option |= OPTION_FLASHONE) #define CLR_OPTION_FLASHONE (_option &= ~OPTION_FLASHONE) #define IS_OPTION_FLASHONE (_option & OPTION_FLASHONE) #define SET_OPTION_FLASHTWO (_option |= OPTION_FLASHTWO) #define CLR_OPTION_FLASHTWO (_option &= ~OPTION_FLASHTWO) #define IS_OPTION_FLASHTWO (_option & OPTION_FLASHTWO) #define SET_OPTION_SLZERO (_option |= OPTION_SLZERO) #define CLR_OPTION_SLZERO (_option &= ~OPTION_SLZERO) #define IS_OPTION_SLZERO (_option & OPTION_SLZERO) class ShiftDisplay { private: byte _clock = DEFAULT_CLOCK; // clock pin number byte _data = DEFAULT_DATA; // data pin number byte _one = 0; // one digit display value byte _two = 0; // two digit display value int _option = 0; // display options ULONG _timerOne = 0; // millisecond timer one digit ULONG _timerTwo = 0; // millisecond timer two digit int _onTimeOne = 1800; // on time for one digit flashing int _offTimeOne = 200; // off time for one digit flashing int _onTimeTwo = 1800; // on time for two digit flashing int _offTimeTwo = 200; // off time for two digit flashing public: ShiftDisplay (); // default constructor ShiftDisplay (byte clock, byte data); // constructor with parameters void begin (byte clock, byte data); // initialization void setClock (byte clock); // set clock pin number byte getClock (); // get clock pin number void setData (byte data); // set data pin number byte getData (); // get data pin number void setHexOne (bool hex); // enable/disable one digit hex mode bool isHexOne (); // true if one digit hex mode void setHexTwo (bool hex); // enable/disable two digit hex mode bool isHexTwo (); // true if two digit hex mode void setDP1 (bool dp1); // enable/disable decimal point 1 bool isDP1 (); // true if decimal point 1 enabled void setDP2 (bool dp2); // enable/disable decimal point 2 bool isDP2 (); // true if decimal point 2 enabled void setDP3 (bool dp3); // enable/disable decimal point 3 bool isDP3 (); // true if decimal point 3 enabled void setBlankOne (bool blank); // enable/disable one digit blank mode bool isBlankOne (); // true if one digit blank mode void setBlankTwo (bool blank); // enable/disable two digit blank mode bool isBlankTwo (); // true if two digit blank mode void setSLZero (bool slzero); // enable/disable suppress leading zero bool isSLZero (); // true if suppress leading zero is enabled void setOnTimeOne (int onTime); // set on time for one digit flashing int getOnTimeOne (); // get on time for one digit flashing void setOffTimeOne (int offTime);// set off time for one digit flashing int getOffTimeOne (); // get off time for one digit flashing void setOnTimeTwo (int onTime); // set on time for two digit flashing int getOnTimeTwo (); // get on time for two digit flashing void setOffTimeTwo (int offTime);// set off time for two digit flashing int getOffTimeTwo (); // get off time for two digit flashing void flashOne (byte one); // flash new one digit value void flashOne (); // flash current one digit value void flashTwo (byte two); // flash new two digit value void flashTwo (); // flash current two ditit value void update (ULONG now); // update for flashing void setOne (byte one); // set one digit value byte getOne (); // get one digit value void setTwo (byte two); // set two digit value byte getTwo (); // get two digit value void outOne (byte one); // output new one digit value void outTwo (byte two); // output new two digit value void out (); // output current values void out (byte one, byte two); // output new values void shift (byte val); // output byte to shift register }; #endif // ShiftDisplay_h