]> fbox.kageds.com Git - richie-water-pump.git/blob - sevseg.h
1st commit
[richie-water-pump.git] / sevseg.h
1 /* SevSeg Library
2
3 Copyright 2017 Dean Reading
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16
17 This library allows an Arduino to easily display numbers in decimal format on
18 a 7-segment display without a separate 7-segment display controller.
19
20 Direct any questions or suggestions to deanreading@hotmail.com
21 See the included readme for instructions.
22 */
23
24 #ifndef MAXNUMDIGITS
25 #define MAXNUMDIGITS 8 // Can be increased, but the max number is 2^31
26 #endif
27
28 #ifndef SevSeg_h
29 #define SevSeg_h
30
31 #if defined(ARDUINO) && ARDUINO >= 100
32 #include "Arduino.h"
33 #else
34 typedef unsigned char byte;
35 #endif
36
37 // Use defines to link the hardware configurations to the correct numbers
38 #define COMMON_CATHODE 0
39 #define COMMON_ANODE 1
40 #define N_TRANSISTORS 2
41 #define P_TRANSISTORS 3
42 #define NP_COMMON_CATHODE 1
43 #define NP_COMMON_ANODE 0
44
45
46 class SevSeg
47 {
48 public:
49 SevSeg();
50
51 void refreshDisplay();
52 void begin(byte hardwareConfig, byte numDigitsIn, byte digitPinsIn[],
53 byte segmentPinsIn[], bool resOnSegmentsIn=0,
54 bool updateWithDelaysIn=0, bool leadingZerosIn=0);
55 void setBrightness(int brightnessIn); // A number from 0..100
56
57 void setNumber(long numToShow, char decPlaces=-1, bool hex=0);
58 void setNumber(unsigned long numToShow, char decPlaces=-1, bool hex=0);
59 void setNumber(int numToShow, char decPlaces=-1, bool hex=0);
60 void setNumber(unsigned int numToShow, char decPlaces=-1, bool hex=0);
61 void setNumber(char numToShow, char decPlaces=-1, bool hex=0);
62 void setNumber(byte numToShow, char decPlaces=-1, bool hex=0);
63 void setNumber(float numToShow, char decPlaces=-1, bool hex=0);
64
65 void setSegments(byte segs[]);
66 void setChars(char str[]);
67 void blank(void);
68
69 private:
70 void setNewNum(long numToShow, char decPlaces, bool hex=0);
71 void findDigits(long numToShow, char decPlaces, bool hex, byte digits[]);
72 void setDigitCodes(byte nums[], char decPlaces);
73
74 bool digitOn,digitOff,segmentOn,segmentOff;
75 bool resOnSegments, updateWithDelays, leadingZeros;
76 byte digitPins[MAXNUMDIGITS];
77 byte segmentPins[8];
78 byte numDigits;
79 byte prevUpdateIdx;
80 byte digitCodes[MAXNUMDIGITS];
81 int ledOnTime;
82 unsigned long prevUpdateTime;
83 };
84
85 #endif //SevSeg_h
86 /// END ///