71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#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 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(int value);
|
|
void writeText(char* value);
|
|
|
|
int getDigits() { return digits; }
|
|
void setDigits(int value) { digits = value; }
|
|
|
|
int getLatchPin() { return latchPin; }
|
|
void setLatchPin(int value) { latchPin = value; }
|
|
|
|
#if defined(SDSupportSPI)
|
|
long getClockSpeed() { return clockSpeed; }
|
|
void setClockSpeed(long value) { clockSpeed = value; }
|
|
#endif
|
|
|
|
#if !defined(SDSupportSPI)
|
|
int getClockPin() { return clockPin; }
|
|
void setClockPin(int value) { clockPin = value; }
|
|
|
|
int getDataPin() { return dataPin; }
|
|
void setDataPin(int value) { dataPin = value; }
|
|
#endif
|
|
|
|
protected:
|
|
void writeDigit(byte value, byte digitMask);
|
|
void writeDisplay(byte characterMask, byte digitMask);
|
|
|
|
private:
|
|
int digits = 6;
|
|
int latchPin = SS;
|
|
|
|
#if defined(SDSupportSPI)
|
|
long clockSpeed = 20000000;
|
|
#endif
|
|
|
|
#if !defined(SDSupportSPI)
|
|
int clockPin = SCK;
|
|
int dataPin = MOSI;
|
|
#endif
|
|
};
|
|
|
|
#endif |