NerfStatTrak/SegmentDisplay.h

76 lines
1.9 KiB
C
Raw Normal View History

#ifndef SegmentDisplay_h
#define SegmentDisplay_h
#include "Arduino.h"
#include "SPI.h"
#include "SegmentDisplayChars.h"
/**
* Drives up to 8 digits using two 8-bit shift registers.
*
* Pushes out the segment bits first and the display selection
* second: connect the display select register first and chain the
* segment register to it's output.
*
* Least significant bit ends up at pin 0, which correlates to
* (as defined in SegmentDisplayChars.h):
* - Last digit
* - Segment A
**/
// Comment to use shiftOut. Set clockPin and dataPin instead.
//#define SDSupportSPI
class SegmentDisplay
{
public:
void begin();
void end();
void writeNumber(uint32_t value);
void writeText(char* value);
byte getDigits() { return digits; }
void setDigits(byte value) { digits = value; }
uint32_t getLatchPin() { return latchPin; }
void setLatchPin(uint32_t value) { latchPin = value; }
uint32_t getDigitDelayMicroseconds() { return digitDelayMicroseconds; }
void setDigitDelayMicroseconds(uint32_t value) { digitDelayMicroseconds = value; }
#if defined(SDSupportSPI)
uint32_t getClockSpeed() { return clockSpeed; }
void setClockSpeed(uint32_t value) { clockSpeed = value; }
#endif
#if !defined(SDSupportSPI)
uint32_t getClockPin() { return clockPin; }
void setClockPin(uint32_t value) { clockPin = value; }
uint32_t getDataPin() { return dataPin; }
void setDataPin(uint32_t value) { dataPin = value; }
#endif
protected:
void writeDigit(byte value, byte digitMask);
void writeDisplay(byte characterMask, byte digitMask);
private:
byte digits = 6;
uint32_t digitDelayMicroseconds = 1000;
uint32_t latchPin = SS;
#if defined(SDSupportSPI)
uint32_t clockSpeed = 20000000;
#endif
#if !defined(SDSupportSPI)
uint32_t clockPin = SCK;
uint32_t dataPin = MOSI;
#endif
};
#endif