-
Notifications
You must be signed in to change notification settings - Fork 1
/
SR7SEGNM.cpp
69 lines (57 loc) · 1.26 KB
/
SR7SEGNM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
|| @file SR7SEGNM.cpp
|| @version 1.0
|| @author ABDUL REHMAN
|| @contact [email protected]
-------------------------------------------------------
*/
#include <SR7SEGNM.h>
const byte SR7SEGNM::segChar[]={
0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111,
0b00000000
};
SR7SEGNM::SR7SEGNM(int clkPin,int dtPin,int strbPin,int nSegments){
clockPin=clkPin;
dataPin=dtPin;
strobPin=strbPin;
numberOfSegments = nSegments;
}
void SR7SEGNM::begin(){
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(strobPin, OUTPUT);
reset();
}
void SR7SEGNM::reset(){
int i=0;
digitalWrite(strobPin, LOW);
for(i=numberOfSegments-1;i>=0;i--){
shiftOut(dataPin, clockPin, MSBFIRST, segChar[0]);
}
digitalWrite(strobPin, HIGH);
}
void SR7SEGNM::updateSegments(int segmentBuffer[]){
int i=0;
digitalWrite(strobPin, LOW);
for(i=numberOfSegments-1;i>=0;i--){
shiftOut(dataPin, clockPin, MSBFIRST, segChar[segmentBuffer[i]]);
}
digitalWrite(strobPin, HIGH);
}
void SR7SEGNM::offAllSegments(){
int i=0;
digitalWrite(strobPin, LOW);
for(i=numberOfSegments-1;i>=0;i--){
shiftOut(dataPin, clockPin, MSBFIRST, 0);
}
digitalWrite(strobPin, HIGH);
}