-
Notifications
You must be signed in to change notification settings - Fork 1
/
SevenSegment.cpp
148 lines (118 loc) · 2.37 KB
/
SevenSegment.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "SevenSegment.h"
SevenSegment::SevenSegment(int pinA, int pinB, int pinC, int pinD)
{
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
_pinA = pinA;
_pinB = pinB;
_pinC = pinC;
_pinD = pinD;
}
void SevenSegment::binaryToDisplay(int statePinA, int statePinB, int statePinC, int statePinD)
{
digitalWrite(_pinA, statePinA);
digitalWrite(_pinB, statePinB);
digitalWrite(_pinC, statePinC);
digitalWrite(_pinD, statePinD);
}
void SevenSegment::displayNumber(int number) {
switch(number) {
case 0:
binaryToDisplay(0, 0, 0, 0);
break;
case 1:
binaryToDisplay(1, 0, 0, 0);
break;
case 2:
binaryToDisplay(0, 1, 0, 0);
break;
case 3:
binaryToDisplay(1, 1, 0, 0);
break;
case 4:
binaryToDisplay(0, 0, 1, 0);
break;
case 5:
binaryToDisplay(1, 0, 1, 0);
break;
case 6:
binaryToDisplay(0, 1, 1, 0);
break;
case 7:
binaryToDisplay(1, 1, 1, 0);
break;
case 8:
binaryToDisplay(0, 0, 0, 1);
break;
case 9:
binaryToDisplay(1, 0, 0, 1);
break;
}
}
/*
*/
void SevenSegment::numberZero(float timer) {
displayNumber(0);
delay(timer);
}
void SevenSegment::numberOne(float timer) {
displayNumber(1);
delay(timer);
}
void SevenSegment::numberTwo(float timer) {
displayNumber(2);
delay(timer);
}
void SevenSegment::numberThree(float timer) {
displayNumber(3);
delay(timer);
}
void SevenSegment::numberFour(float timer) {
displayNumber(4);
delay(timer);
}
void SevenSegment::numberFive(float timer) {
displayNumber(5);
delay(timer);
}
void SevenSegment::numberSix(float timer) {
displayNumber(6);
delay(timer);
}
void SevenSegment::numberSeven(float timer) {
displayNumber(7);
delay(timer);
}
void SevenSegment::numberEight(float timer) {
displayNumber(8);
delay(timer);
}
void SevenSegment::numberNine(float timer) {
displayNumber(9);
delay(timer);
}
/*
*/
void SevenSegment::chooseNumbers(int numberFirst, int numberSecond, float timer) {
if (numberSecond > numberFirst) {
for (int i = numberFirst; i <= numberSecond; i++) {
displayNumber(i);
delay(timer);
}
} else if (numberFirst > numberSecond) {
for (int i = numberFirst; i >= numberSecond; i--) {
displayNumber(i);
delay(timer);
}
}
}
/*
*/
void SevenSegment::allNumbers(float timer) {
for (int i = 0; i < 10; i++) {
displayNumber(i);
delay(timer);
}
}